Switch active drawing Standard with iLogic

Switch active drawing Standard with iLogic

Jesse_Glaze
Participant Participant
180 Views
5 Replies
Message 1 of 6

Switch active drawing Standard with iLogic

Jesse_Glaze
Participant
Participant

I am looking for a (hopefully) simple code that would allow me to activate a different drawing standard.

This rule would also be used for updating old drawings, so it should work even if the standard is saved to the style library but not saved in the local document.

 

Jesse_Glaze_0-1755541530732.png

 

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

WCrihfield
Mentor
Mentor

Are you aware of the relatively simple manual steps to do that?

Starting from drawing visibly open on your screen, go to the 'Tools' tab and click on the 'Document Settings' button in the Options panel of the ribbon.  Activate the 'Standard' tab (if not already active), then use the drop-down list to switch to any other drawing standard style.

Other than that manual process, how would you need to be able to specify which standard the drawing should be switched to?  That step along may be 'relatively' simple to do by code, depending on what may be required to retrieve it from some other external source when it does not exist in the current drawing.  But then, what are your expectations or requirements about what should happen after that specified standard is activated?  If you are expecting every type of pre-existing annotation or dimension on every sheet of the drawing to instantly be updated to match that standard style, that usually requires a pretty long and complex code process, which usually also requires some further local customization.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Jesse_Glaze
Participant
Participant

Yes, I know how to do it manually. Yes, that should be easy.

 

More Context

I will have a few different standards and a few different title blocks, each used for a different drawing type. To make this simple, I am creating a form with a button for each drawing type. Click the button, launch a rule that sets the drawing up for the user. I know how to swap title blocks. I just need the piece of ilogic that will allow me to switch standards. No other function required.

 

I am not trying to pull standards from "some other external source". I have the proper standards saved to the styles library, which is shared by all users. That doesnt mean the standards will be saved to all documents where this rule is run.

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

OK.  I'm on my way out for the day, but I will post one of the Sub routines out of one of my external rules that I use for that part of it.  I have several external rules that get ran when I want to update an older, pre-existing drawing to newer standards, but this was an internal method.  It lets me pass the DrawingDocument, and style name to it, then it looks for that style, and if it is a 'library' one, it converts it to a local style, then activates it.  I set the second input as Optional, for use with a 'default' style, to potentially simplify things elsewhere.  I will check back tomorrow.  Have a nice day.

Sub SetActiveDrawingStandardStyle(oDrawDoc As DrawingDocument, _
	Optional styleName As String = Nothing)
	Const sDefaultStyleName As String = "Default"
	If String.IsNullOrWhiteSpace(styleName) Then
		styleName = sDefaultStyleName
	End If
	Dim oSMgr As DrawingStylesManager = oDrawDoc.StylesManager
	Dim oStStyle As DrawingStandardStyle = Nothing
	Try
		oStStyle = oSMgr.StandardStyles.Item(styleName)
	Catch oEx As Exception
		Logger.Error("Failed to find specified DrawingStanardStyle to make active." _
		& vbCrLf & oEx.Message & vbCrLf & oEx.StackTrace)
	End Try
	If Not oStStyle Is Nothing Then
		If oStStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
			oStStyle = oStStyle.ConvertToLocal()
		ElseIf oStStyle.StyleLocation = StyleLocationEnum.kBothStyleLocation Then
			oStStyle.UpdateFromGlobal()
		End If
		oSMgr.ActiveStandardStyle = oStStyle
	End If
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Attached in a text file is another version of that method, as a Function which returns a Boolean indicating the success or failure of the method.  In this version all of the input variables have been made Optional, and it has a third option which asks the user if they want to choose a style from a List of style names, which has a default value of False.  If that last option is specified as True, then an internal block of code will create that list of names, present it to the user, capture their selection (if any), then set that chosen name as the one to be obtained, and set as the active one later in that method.  If the DrawingDocument is not specified, then it will first check if the 'active' Document is a drawing, and if so, will use that.  If the active one is not a drawing, it will next check the Type of Document the 'ThisDoc.Document' iLogic phrase is pointing to, and if it is a drawing, will use that, but if it's also not a match, it will exit the routine.  You will likely want to change the 'default' style name being specified within the method to suit your needs, if you want to avoid user interactions as much as possible.  If there are just a few specific styles that you will be choosing between, then you could potentially use a custom 'Enum' to specify which one you want, then have those static (hard-coded) names right within the method, which would be chosen by the value of the input Enum variation.  Lots of possibilities there.  Since you are creating a Form, the Application object and Document object will likely already be 'global' variables within your overall code resource, so you may want to swap some of those 'iLogic' references out for those 'global' variable references also.  Just some additional ideas.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Jesse_Glaze
Participant
Participant

The first piece of code you provided worked perfectly! I tweaked it slightly to make the style not optional and removed the default portion. Thank you for your help!

0 Likes