I logic to choose certain dim styles

I logic to choose certain dim styles

didin.suryadi6JREK
Advocate Advocate
887 Views
8 Replies
Message 1 of 9

I logic to choose certain dim styles

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

I want to create an i-logic to choose certain dim styles in inventor drawing. Basically, the list box appears to choose the style. I have tried with the below code but didn't work.

 

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oDSMgr As New List(Of String)
For Each oNewStyle As DimensionsStandardStyle In oDSMgr.DimensionStyles.Item
	oSStyles.Add(oSS.Name)
Next
oChoice = InputListBox("", oNewStyle, "", "Dimension Standard Styles", "Dimension Standard Styles List")
If String.IsNullOrEmpty(oChoice) Then Exit Sub
Dim oNewStyle As DimensionStyle = oDSMgr.DimensionStyles.Item (oChoice)
oDDoc.StylesManager.ActiveStandardStyle = oNewStyle

 

0 Likes
Accepted solutions (3)
888 Views
8 Replies
Replies (8)
Message 2 of 9

theo.bot
Collaborator
Collaborator
Accepted solution

You can not simply set the active style that you would like to use. In the user interface you can't set the active style if there is no command ( like dimension,  balloon etc) is active. The default style that will be used is defined in the object defaults style. So you could manipulate this one every time or you can pick a style and apply it when creating an drawing object. i created a simple sample:

 

Sub main
	
Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oDSMgr As New List(Of String)
Dim oStyle As DimensionStyle
For Each oStyle In oDoc.StylesManager.DimensionStyles
	oDSMgr.Add(oStyle.Name)
Next
oChoice = InputListBox("", oDSMgr, "", "Dimension Standard Styles", "Dimension Standard Styles List")
oStyle = oDoc.StylesManager.DimensionStyles.Item(oChoice)

ThisDrawing.BeginManage()
 ' Statements to add dimensions, annotations, etc. go here.
 Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim namedGeometry1 = VIEW1.GetIntent("Right")
Dim namedGeometry2 = VIEW1.GetIntent("Left")
Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW1.SheetPoint(0.5, -0.1), namedGeometry1,namedGeometry2,,,,oStyle)
 
ThisDrawing.EndManage()



End Sub

 

Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @didin.suryadi6JREK.  Are you just trying to change the dimension style temporarily, like just for a single dimension placement, or are you trying to change the dimension style more permanently?  If you would just like to choose another dimension style to use for a specific dimension here and there, I would recommend that you activate the 'Annotate' tab in your drawing environment, then make sure that the 'Format' panel is showing in the ribbon.  Then anytime you activate a tool to place a dimension or other annotation onto your drawing, simply choose another style from the 'Style' drop-down list in that 'Format' panel.  That's what I always do.

 

However, if there are several things in the drawing that I would like to do using different styles than normal, I have other 'Stantard Styles' set-up in my Styles Manager, and when I want to consistently use some different styles for a while, I go to the 'Tools' tab > Document Settings > Standard tab, then choose one of my other 'Standard' styles, in which those things are set-up.

 

If you want to change the 'default' dimension style for a certain type of dimension, you may already know that within the Styles & Standards editor in a drawing, there are styles called Object Defaults, and one of them is used in each main Standard style.  You can change the specific setting in there, either manually, or by code.  You could then save those changes back to the styles library if you wanted, so they would be available to other drawings.  I have multiple main Standard styles for different situations, which can save a ton of time in the long run.  If you want to access those defaults from code though, you just have to dig down into the styles manager to get to them.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

didin.suryadi6JREK
Advocate
Advocate

Hi,

 

Thanks for the reply.

Actually, I want the dimension styles list to come up as a selection, So when I run it the msg box with the list will come up and let me choose the desired one.

 

didinsuryadi6JREK_0-1634000698777.png

Rgrds

 

Din

0 Likes
Message 5 of 9

didin.suryadi6JREK
Advocate
Advocate

Hi 

 

Thanks

 

I use the below particular codes from your post, The selection box is coming but the entire dimension styles, balloons, etc didn't update by themself. Could you please explain why?

 

Dim oDoc As DrawingDocument = ThisDrawing.Document
Dim oDSMgr As New List(Of String)
Dim oStyle As DimensionStyle
For Each oStyle In oDoc.StylesManager.DimensionStyles
	oDSMgr.Add(oStyle.Name)
Next
oChoice = InputListBox("", oDSMgr, "", "Dimension Standard Styles", "Dimension Standard Styles List")
oStyle = oDoc.StylesManager.DimensionStyles.Item(oChoice)

 

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

This type of code, that simply lets you select a dimension style from a list, then gets that dimension style, will not set the selected dimension style as the new default dimension style for further manual dimensioning.

 

There are only two ways to use a non-default dimension style for new manually placed dimensions.

  • After you click on a tool to place a dimension (or other related drawing annotation), but before placing that dimension (or other annotation), select the style you want to use from the Annotate tab > Format panel's Style drop-down list, then place your dimension (or other annotation).
    • That chosen style will reset back to the default style once that command ends.
  • Choose a different Standard style within the Tools tab > Options panel > Document Settings > Standard tab > Active Standard drop-down list.  Then click Apply in that dialog.  Then place some dimensions or annotations.  When done using these other styles, switch back to your normal Standard style, using this same process.

As I said before, we could add more code to the rule after the selection, that would attempt to change one (or more) of the settings within the ObjectDefaults of the active Standard style to the dimension style you have chosen.  That would make this setting stick after the rule is finished.  Or we could just have the rule present you with the list of Standard styles, have you choose one, then set that chosen Standard style as the active one.  This other Standard style could have other dimension styles set as its default ones to use.  But these are pretty much the only options here.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

didin.suryadi6JREK
Advocate
Advocate

Thanks, Ok I got it

 

Just wondering why the dims, balloon etc didn't want to automatically update after we choose certain styles,

I won't complain to my brain, but this sounds a little bit weird.

This is happening a lot when I update the old drawing with the previous styles, When I want to change to the new styles this code won't work anyways. 

 

Rgds

 

 

0 Likes
Message 8 of 9

theo.bot
Collaborator
Collaborator
Accepted solution
When creating drawing objects like dimensions and balloons there is a style definition used. Only if you would select them in a drawing you can change it into a different style. If you make changes to the style that is used for the objects it will update the existing objects in your drawing.
0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor
Accepted solution

No worries.  Dealing with drawing styles, whether manually, or by code, can be a major pain even for the best of us. 😏

OK.  So you also want to be able to either update or change the styles of existing dimensions and annotations, right? 

So, basically when a style gets updated in a drawing, then any existing elements in that drawing that are already currently using that style should be automatically updated too.  However, simply switching which Standard style you are using (manually, in the Document Settings) will not change any existing elements to those other default styles...it will only effect any new elements you add to the drawing.  If you want to change the style that existing elements are currently using to a different style, you need to select those elements, then use the Format panel to choose another available (and compatible) style, then they will be using that chosen style.  Or if you want to change their styles by code, you would need to loop through them all (can be multiple types of objects) and set their Style property's value to the other one.  It can be a slightly complicated process, but I'm sure the are codes like that here on this forum, because I've participated/contributed some myself in the past.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes