Engineer's Scale |
I recently ran into a situation where the client wanted two methods to pull a drawing scale to include in the title block:
- Find the view name with the lowest numerical value and use its scale in the title block
- Present the user with all drawing views, and their scales, on a drawing and allow the user to select which view he/she wanted to represent the scale in the title block
I'll discuss the first solution in this blog post. The solution included just a few steps.
We cycled through each sheet on the drawing and looked at each view name. If the view name begins with "VIEW" then it was used to build an one dimensional array. This step ensured we didn't pull views such as section or detail views.
' Cycle thru each sheet. Build array of View Name and View Scale. For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews oViewName = oView.Name If Left(oViewName,4) = "VIEW" Then temp = Right(oViewName,1) oViewList.Add(temp) End If Next Next
We then sorted the array and pulled the view scale of the first index of the array.
' Sort array oViewList.Sort ' Get scale of lowest View oSelectedScale = ActiveSheet.View("VIEW" & oViewList(0)).Scale
The view scale was pushed to a custom iProperty that was displayed in the drawing title block.
' Set custom iProperty based on user selection iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _
RoundingMethod.Round) & ":1"
The full code is listed here:
' Setting Variables Dim oDrawDoc As DrawingDocument = ThisDrawing.Document Dim oSheet As Sheet Dim oSheets As Sheets oSheets = oDrawDoc.Sheets Dim oView As DrawingView Dim oViews As DrawingViews Dim oScale As Double Dim oViewName As String Dim oViewList As New ArrayList ' Cycle thru each sheet. Build array of View Name and View Scale. For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews oViewName = oView.Name If Left(oViewName,4) = "VIEW" Then temp = Right(oViewName,1) oViewList.Add(temp) End If Next Next ' Sort array oViewList.Sort ' Get scale of lowest View oSelectedScale = ActiveSheet.View("VIEW" & oViewList(0)).Scale ' Set custom iProperty based on user selection iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _ RoundingMethod.Round) & ":1" ' Update iLogicVb.UpdateWhenDone = True
Next post I'll discuss the second option where we displayed the view names and scales and allowed the user to select which scale to use in the title block.
As always, leave a comment and let us know how this has helped you.
Randy
"The difference between try and triumph is a little umph." - Unknown
Very nice Randy. Exactly what I was looking for. However the way you present the scale seem alittle odd to me; "1/4:1", "1/8:1" etc. Do you have any idea how I should do to present it in a regular manner i.e. "1:4", "1:8" etc
ReplyDeleteThanks,
Rickard
Rickard,
DeleteYou can change the block that sets the custom iProperty to something like below:
' Set custom iProperty based on user selection
oRoundedScale = RoundToFraction(oSelectedScale, 1/8, RoundingMethod.Round)
If oRoundedScale.IndexOf("/") > 0 Then
iProperties.Value("Custom", "Scale") = oRoundedScale.Replace("/",":")
Else
iProperties.Value("Custom", "Scale") = oRoundedScale & ":1"
End If
This will check the string for '/' and if it finds it, it will replace with ':'. If it doesn't find one, it appends ':1' at the end.
Thanks,
Randy
Hi Randy
DeleteActually I just found an easier solution:
' Get scale of lowest View
oSelectedScale = ActiveSheet.View("VIEW" & oViewList(0)).ScaleString
' Set custom iProperty based on user selection
iProperties.Value("Custom", "Scale") = oSelectedScale
That makes the scale format correct. However, the code is not stable if you remove or change name of views. E.g. "VIEW0" is renamned to "VIEW1", then an error will occur because the ilogic rule is still searching for "VIEW0".
Thanks,
Rickard
Hi Randy
DeleteDo you have any idea how to make this ilogic rule to work even if you delete or rename the view with the lowest number? It seems like the rule remembers the temporary view list that was created when runned the previous time.
Is it possible to start the code by clearing the previous list?
Thanks,
Rickard
Hi Rickard,
ReplyDeleteThe code as written above accomplishes that. When the oViewList is declared, it is cleared. If you're renaming views, be sure to keep 'View' as part of the name.
Hi Randy
ReplyDeleteIf found the root cause for my problems.
If the drawing contains >10 views, starting at "VIEW1" to "VIEW10". Then the code will search for the last single character in "VIEW10", which returns "0". Error message will say "No drawing view named "VIEW0" was found"
Thats a tricky one!
Thanks,
Rickard
Hi Randy
ReplyDeleteI made some changes to be able to have >10 views. Also, I added a test if there is no existing view at all.
' Setting Variables
Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet
Dim oSheets As Sheets
oSheets = oDrawDoc.Sheets
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oScale As Double
Dim oViewName As String
Dim oViewList As New List(Of Integer)
' Cycle thru each sheet. Build array of View Name and View Scale.
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
oViewName = oView.Name
If Left(oViewName,4) = "VIEW" Then
temp = oViewName.Substring(4)
oViewList.Add(temp)
End If
Next
Next
' Sort array
oViewList.Sort
' Get scale of lowest View on Sheet 1
If oViewList.Count >=1 Then
oSelectedScale = ThisDrawing.Sheet("Sheet:1").View("VIEW" & oViewList(0)).ScaleString
ElseIf oViewList.Count = 0 Then
oSelectedScale = "-"
End If
' Set custom iProperty based on user selection
iProperties.Value("Custom", "FirstViewScale") = oSelectedScale
This code demands the view with lowest number to be on sheet 1. I can't really figure out how to cycle through only sheet 1 instead of cycle through all sheets.
Thanks,
Rickard