Rule to update annotation style on drawing

Rule to update annotation style on drawing

Shag_Bore
Advocate Advocate
1,489 Views
6 Replies
Message 1 of 7

Rule to update annotation style on drawing

Shag_Bore
Advocate
Advocate

I am trying to use an old rule that worked for me years ago but am having trouble setting it up again.

The rule utilizes an user parameter that gives the option for the user to select what dimension style to use on a drawing when starting up.

Here is my parameters:

parameters.png

 

Here is the styles library showing the available options

styles_library.PNG

 

and lastly here is the rule, I am not sure to why it isn't applying the selected dimension style.

 

 

' To use this rule, create a Text parameter named Standard in the drawing.
'  Assign it values such as:
' ANSI
' ANSI-mm

doc = ThisDoc.Document
customPropertySet = doc.PropertySets.Item("Inventor User Defined Properties")
 
'Make sure drawingUNITS property exists
Try
      prop = customPropertySet.Item("drawingUNITS")
Catch
      'Assume error means not found
      customPropertySet.Add("", "drawingUNITS")
End Try

Dim drawingDoc as DrawingDocument = ThisDoc.Document

For Each standardX In drawingDoc.StylesManager.StandardStyles
 Dim internalName As String = standardX.InternalName
 Do
   Trace.WriteLine(" -- internalName = " & internalName)
   Dim ch As Char = internalName(internalName.Length-1) 
   If (ch <> vbCr And ch <> vbLf And ch <> ")" And ch <> " ") Then Exit Do
   internalName = internalName.SubString(0, internalName.Length-1)
 Loop
 Trace.WriteLine(String.Format(" Style: {0}, {1}", standardX.Name, internalName))
  
 If (internalName.EndsWith(Standard, StringComparison.OrdinalIgnoreCase)) Then
   drawingDoc.StylesManager.ActiveStandardStyle = standardX
   Trace.WriteLine(" --- Changed the active drawing standard to " & standardX.Name & "...")
   Exit For
 End If 
Next

iProperties.Value("Custom", "drawingUNITS") = Standard

InventorVb.DocumentUpdate()

Exit Sub
handleErrors:
'do nothing 

 

EDIT:

 

I found out that the rule is calling out the ANSI, ANSI-mm from the standard section of the style library, I thought it was pulling the dimension styles from the active standard. Is a way to edit the rule to allow me to select the dimension styles?

 

styles_library_2.PNG

Sean Farr
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB
0 Likes
Accepted solutions (1)
1,490 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @Shag_Bore.  My initial thoughts here are that your code is dealing with 'StantardStyles' and their names, but your images are looking at DimensionStyles and their names.  Those are two different API objects.  I only see 2 StandardStyles in the second image ("Default Standard (ANSI)" & "Teksign_2022").

 

Edit:  Saw your edited post after posting, so disregard this post.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

Shag_Bore
Advocate
Advocate

I did some digging, found some rules that I parged together, I had this working until I saved the drawing sheet as a a new template and now it isn't working again. Something to do with my styles, after I renamed the ANSI styles to " in, mm, ft, ft [mm], it reverted them back to there original names like Default (ANSI), Architectural (ANSI)

 

I will have to see what I am doing wrong in the style library but anyhow here is the working rule, just have to change the parameter names to match exactly what you Dimension style names are that you want to use. 

 

'check for parameter and create if not found
Try
oTest = Parameter("DimStyle") 
Catch
'multi-value text Parameter
ThisDoc.Document.Parameters.UserParameters.AddByValue("DimStyle", "in", UnitsTypeEnum.kTextUnits)
'Set list
MultiValue.SetList("DimStyle", "in", "ft", "mm", "ft [mm]")
End Try
Parameter.Param("DimStyle").IsKey​ = True

iLogicVb.UpdateWhenDone = True

 
'define the drawing document
Dim oDrawDoc As DrawingDocument = ThisDoc.Document

'look at each sheet
For Each oSheet In oDrawDoc.Sheets 
	'reference to the style manager
	Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
	
	'get the reference to the target dimension style (by name)
	Dim oDimStyle As DimensionStyle 
	
	If DimStyle = "in" Then
		oDimStyle = oStylesMgr.DimensionStyles.Item("in")
	End If
	If DimStyle = "mm" Then	
		oDimStyle = oStylesMgr.DimensionStyles.Item("mm")
	End If
	If DimStyle = "ft" Then
		oDimStyle = oStylesMgr.DimensionStyles.Item("ft")
	End If
	If DimStyle = "ft [mm]" Then
		oDimStyle = oStylesMgr.DimensionStyles.Item("ft [mm]")
	End If
	
	'change general dimensions
	Dim oDims As DrawingDimensions = oSheet.DrawingDimensions
	For Each oDim As GeneralDimension In oDims
		oDim.Style = oDimStyle
	Next
	
	'change Hole and Thread Notes
	Dim oThreadNote As HoleThreadNote
	For Each oThreadNote In oSheet.DrawingNotes.HoleThreadNotes
		oThreadNote.Style = oDimStyle
	Next
Next 'sheet 
Sean Farr
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB
0 Likes
Message 4 of 7

Shag_Bore
Advocate
Advocate

The rule works but is not perfect, right now I have the template setup to prompt the form on new document. The form appears and there option to select the desired dimension style and the drawing sheet size. After pressing the update drawing the sheet resizes but the dimension styles do not start correctly. 

 

The annotating is still set to the object defaults (in my case ft [mm]) even though I selected say inches in the form prompt. 

 

Once I place an initial dimension on a view, I can then open the form back up and select the correct dim style I want and update and it works. 

 

Not a big deal, but if possible, can the rule be fixed so that is applies the correct dim style on drawing start up form prompt and not after first drawing view and dimension is placed?

 

I attached the template here. 

 

Thanks!

Sean Farr
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB
0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Hi @Shag_Bore.  If you want new dimensions you create after running the rule to be the same style as you are changing the other pre-existing dimensions to be, you will need to make those changes within the Object Defaults portion of the DrawingStandardStyle.  The settings in there dictate which styles will be used by default in different situations.  There are a lot of settings within the Object Defaults though, so you may want to deal with that part manually, within the Styles Editor dialog.  Within that dialog, when you have your active Standard style selected, you will see several tabs to the right.  One of those tabs is Object Defaults.  Within that tab there is one setting at the very top of it...a drop-down list for the 'active' Object Defaults.  That is the one that is being used by that Standard style.  You can edit that Object Style by selecting that one within the main list on the far left, then editing the settings on the right.  Once you get this the way you want it, save it.  When you save it though, it will only exist in that document, so if you want to be able to use the same settings within other documents, right click on the main style in the main list on the left, then choose 'Save to Style Library'.  If you saved an edited Object Defaults to the library, you will also want to save the Standard style it is used within to the style library, so that everything is up to date.  Some of this could probably be done by code, but that could turn into a very long code, and if done right, it most likely will only need to be done once.  Then within other older documents, you can set the 'active' standard style to your updated one, and if pre-existing dimensions are using the same styles, they will automatically be updated too.  But if pre-existing dimensions are set to other styles, you will have to loop through them and change their styles, similar to what your code is doing now.

 

This process can be done manually fairly quickly and easily too.

  • On Tools tab > Options panel, click Document Settings.  Then on the Standard tab, choose the Standard you want to use.
  • WCrihfield_2-1661366850197.png

     

  • On the Manage tab > Styles and Standards panel, click Update.  Then click 'Yes to All' button, and 'OK' button.

WCrihfield_3-1661366944915.png

 

  • On quick access tool bar, click the drop-down beside the Selection Preferences tool, and choose 'Select All Inventor Dimensions'.

WCrihfield_1-1661366752593.png

  • While all the dimensions are selected, go to the Annotate tab > Format panel, and choose the Dimension Style you want to set them all to.

Now all existing styles and dimensions are fully updated, and all new dimensions you create will be according to the Object Defaults settings of the Standard style you just set as 'active'.

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

Shag_Bore
Advocate
Advocate

Thanks @WCrihfield , good information!
Maybe I should give a little more detail of what I am trying to do. I want a "One Stop Shop" drawing template. I do many drawing variations. Some require basic dimensions ( in ft), our fabricators want inches, and some others want dual dims. Plus we can print up to size E drawing sheets. 

 

I was hoping to a template created where with 1 or 2 clicks I have the sizes and styles setup. I pretty much have it done except for one little setback, the dim styles need to be changed via my ilogic code after the first view and dim is placed. I pieced together the rule off other posts and don't know enough iLogic if the rule can be edited to enable the proper the dim style (object default) prior to placing views. 

 

Thanks!

Sean Farr
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB
0 Likes
Message 7 of 7

Shag_Bore
Advocate
Advocate
Accepted solution

I managed to figure out how to achieve my goal with the help of the experts on here!

This post is how to set up new Dimension Styles and Object Default Styles

This post has the iLogic rules needed to apply those Object Defaults, it can done thru a form or an event can be set up to trigger the rule on drawing start-up, dealers choice.

 

Thanks!

 

Sean Farr
Product Designer at Teksign Inc.
Inventor 2016 SP1
Dell Precision 3660
i7-12700 @ 2.40GHz-4.90GHz
32GB DDR5 4400MHz RAM
NIVDIA RTX A2000 6GB
0 Likes