Help with toggling the duel dimension units on existing drawings

Help with toggling the duel dimension units on existing drawings

austin.massey6W6WX
Explorer Explorer
686 Views
5 Replies
Message 1 of 6

Help with toggling the duel dimension units on existing drawings

austin.massey6W6WX
Explorer
Explorer

I have many existing drawings that would take a long time to recreate and manually switch the primary and secondary units of the dual dimension style that I'm using. I need help with creating a iLogic rule to give the user the option to toggle the dual dimensioning units. I have a form that asks the user which units (imperial or metric) and would like this to control the primary unit while the secondary unit is the latter.

 

Any suggested codes?

0 Likes
Accepted solutions (1)
687 Views
5 Replies
Replies (5)
Message 2 of 6

Andrii_Humeniuk
Advisor
Advisor

Hi @austin.massey6W6WX . To get started, you need to add the "Model_Units" text parameter:
Step1.png

Next, you need to write in line 3 "Default (GOST)" the name of the style you use for your dimensions

 

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oUnits As UserParameter = oDDoc.Parameters.UserParameters("Model_Units")
Dim oDStyle As DimensionStyle = oDDoc.StylesManager.DimensionStyles("Default (GOST)")
If oUnits.Value = "Imperial (Standard)" Then
	oDStyle.LinearUnits = UnitsTypeEnum.kInchLengthUnits
	oDStyle.AlternateLinearUnits = UnitsTypeEnum.kMillimeterLengthUnits
Else
	oDStyle.LinearUnits = UnitsTypeEnum.kMillimeterLengthUnits
	oDStyle.AlternateLinearUnits = UnitsTypeEnum.kInchLengthUnits
End If

 

Make sure that the names in the strings match yours, otherwise it may cause errors.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 6

austin.massey6W6WX
Explorer
Explorer

We added those lines into our code

austinmassey6W6WX_0-1691064967468.png

 

 

Then we got an error; Not sure what this error refers to.

austinmassey6W6WX_1-1691064967469.png

 

 

 

 

If we remove Line 1 we get these errors.

austinmassey6W6WX_2-1691064967471.png

 

 

Could you walk through what each step is doing?

Is this a VB code? The last line shown was how we were able to get the value of our User Parameter (before adding you code up top). I don’t understand the significance between how your code functions and mine?

0 Likes
Message 4 of 6

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @austin.massey6W6WX . I've added a Try-Catch method to each line so that in the event of an error, it will show you a problem message.

Dim oDDoc As DrawingDocument
Try
	oDDoc = ThisDoc.Document
Catch
	MessageBox.Show("Active document is not drawing document", "Error 1!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End Try
Dim oUnits As UserParameter
Try
	oUnits = oDDoc.Parameters.UserParameters("Model_Units")
Catch
	MessageBox.Show("Failed to get parameter 'Model_Units'", "Error 2!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End Try
Dim oDStyle As DimensionStyle
Try
	oDStyle = oDDoc.StylesManager.DimensionStyles("Default-in[mm] (ANSI)")
Catch
	MessageBox.Show("Failed to get DimensionStyle", "Error 3!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End Try
Try
	If oUnits.Value = "Imperial (Standard)" Then
		oDStyle.LinearUnits = UnitsTypeEnum.kInchLengthUnits
		oDStyle.AlternateLinearUnits = UnitsTypeEnum.kMillimeterLengthUnits
	Else
		oDStyle.LinearUnits = UnitsTypeEnum.kMillimeterLengthUnits
		oDStyle.AlternateLinearUnits = UnitsTypeEnum.kInchLengthUnits
	End If
Catch
	MessageBox.Show("Failed to change dimension", "Error 4!",MessageBoxButtons.OK,MessageBoxIcon.Error)
End Try

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @austin.massey6W6WX.  I had another couple of iLogic rules in my collection that you may like, for essentially the same task, except they are not really specific to 'duel units', they are just for setting a specific DimensionStyle to all existing dimensions in an existing drawing.  They were both originally designed with slightly different first steps in mind, but basically the same final steps in mind.  One rule specifies the DimensionStyle name as a 'static' value right within the rule's code, so it is slightly less flexible, but still just fine.  Then the other rule was meant to be used after you have opened an old drawing, then changed which 'Standard Style' is the 'active' one, within the Document Settings, then run that rule and the rule will update all styles to match what that active Standard Style dictates.  Those two rules are attached as text files, because they are somewhat long.  The one with its name starting with "Change" has been customized to look for the style you seemed to be specifying in the screen shot image you posted above.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

austin.massey6W6WX
Explorer
Explorer

@Andrii_Humeniuk that did the trick. I initially got an error at "Failed to get DimensionStyle", "Error 3!" and we realized it was due to spacing in "Default-in[mm] (ANSI)".

 

I changed it to "Default - in [mm] (ANSI)" and the code worked perfectly.

 

Thank you for the support!

0 Likes