Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic code to change Active Default Standard

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
iancross
1055 Views, 2 Replies

ilogic code to change Active Default Standard

Hi Guys,

this tiny bit of code is driving me mad. keep running into a brick wall.

 

i am after a slice of iLogic code which will change the Active Standard Style to what ever i need. 

 

i.e. my active Standard style is Default ISO but i also i have a Standard call Company XYZ (ISO) i want to be able to run an ilogic code to change the Active standard

 

Default style.png

Ian Cross
www.xcrosstech.com
Vault, Inventor, and MFG Specialist
Across Technology, Across Industry
2 REPLIES 2
Message 2 of 3
iancross
in reply to: iancross

i worked this out and it works just as i want

 

SyntaxEditor Code Snippet

 Const kStandardName = "ABC" 
    Const kObjDefaultsName = "My Defaults" 
    Dim oDoc As DrawingDocument 
    
    On Error Resume Next 
    
    oDoc = ThisApplication.ActiveDocument 
    Dim oStylesMgr As DrawingStylesManager 
    oStylesMgr = oDoc.StylesManager 
    Dim oStandard As DrawingStandardStyle 
    
    oStandard = oStylesMgr.StandardStyles _ 
                             .Item(kStandardName) 
    
    If oStandard Is Nothing Then 
        oStandard = oStylesMgr.StandardStyles _ 
                       .Item(1).Copy(kStandardName) 
    End If 
    
    oStylesMgr.ActiveStandardStyle = oStandard
Ian Cross
www.xcrosstech.com
Vault, Inventor, and MFG Specialist
Across Technology, Across Industry
Message 3 of 3
ewiggers
in reply to: iancross

Hello,

 

You are using an On Error Resume Next in your code, I have some advice on that. With On Error Resume Next your telling your code that if something went wrong it has to ignore that line of code and go on with the next line. I suggest that If something went wrong you better handle that properly because it didn't went wrong without a reason, so handle errors and don't just ignore them.

 

It is also difficult to find errors in your code because the code executes each line and when your rule ends nothing happened and you end up searching for a long time about what went wrong. So please delete the On Error Resume Next line from your code and don't use this anymore.

 

If you assign values to an object it is best to start an If Then Else End If statement to determine if the object is not nothing. This way you avoid Errors because a object is not assigned and your code will go into the right direction. For debug purpose it is also simple to put MsgBox statements at strategic points in your code. With the On Error Resume Next statement the code will always excecute the next line and never reach your debug or control point.

 

To catch and handle errors it is best to use Try, Catch, End Try statements in your code. With this statement the code jumps to the Catch statement and there you can handle things.

 

Regards,

Eelco

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report