Using iLogic to change dimension styles on drawing

Using iLogic to change dimension styles on drawing

josephcooley
Advocate Advocate
3,940 Views
5 Replies
Message 1 of 6

Using iLogic to change dimension styles on drawing

josephcooley
Advocate
Advocate

Hi we have two dimesnions styles that we use "Style, ANSI" and "Style, ISO"  I've been trying to figure out how to make a switch in a form that will allow you to change all the dimension styles on all the sheets in drawing.  So far I have not been able to figure it out. I'd really appreciate some help if anyone knows how to get this to work.  It needs to be able to switch back and forth also.

Accepted solutions (1)
3,941 Views
5 Replies
Replies (5)
Message 2 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

HI josephcooley,


Attached is an example file with an iLogic rule and a form that runs the rule. The file is an Inventor 2015 file. I've attached the code here also, in case you can open the file.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'check for parameter and create if not found
Try
oTest = Parameter("DimStyle") 
Catch
'create multi-value text parameter
ThisDoc.Document.Parameters.UserParameters.AddByValue _
("DimStyle", "ANSI", UnitsTypeEnum.kTextUnits)

'set list
MultiValue.SetList("DimStyle", "ANSI", "ISO")
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 = "ANSI" Then
		oDimStyle = oStylesMgr.DimensionStyles.Item("Style, ANSI")
	Else
		oDimStyle = oStylesMgr.DimensionStyles.Item("Style, ISO")
	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 

EESignature

Message 3 of 6

josephcooley
Advocate
Advocate

Wow that is awesome I was just hoping for a little help but this is a full solution thank you so much!

0 Likes
Message 4 of 6

josephcooley
Advocate
Advocate

OK So Ive been using this rule for a little bit now and I seem to have run into a bit of snag.  I have another dimension style that I Use for elevations called "Elevations (US)" When i put those styles on a drawing the rule threw this error:

 

Error in rule: Template Selection, in document: StormKing General Arrangement.dwg

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.GeneralDimension'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EE21CD75-39FD-4683-BE24-BFBB9CA66EB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

The info tab is this:

 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.GeneralDimension'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EE21CD75-39FD-4683-BE24-BFBB9CA66EB4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I have confirmed that if I take the different dimension style off of the drawing it stop having the error.  Like the regular dimension styles there is a us and metric version so those need to be switched when the units are switched also.  A single drawing can have both styles.  Do you have any suggestions on how to fix this?

0 Likes
Message 5 of 6

Anonymous
Not applicable

I would like to use a code like this to run and change everything to inches or to millimeters, is there a way to do that? It would be greatly appreciated for any help you have!

0 Likes
Message 6 of 6

RoyWickrama_RWEI
Advisor
Advisor

Hi Curtis;

 

II like the code because soon it will be helpful for me.

 

Currently, I have a multi-sheet drawing with D, B and A sheet sizes (that includes all the drawings for a small sub-assembly).

I have tree drawing standards:

STD A-Size

STD B-Size

STD D-Size

 

Could you help with a coding for switching the drawing style for the active sheet.

 

Drawing Standard.png

0 Likes