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 to set Sheet Metal style to known component

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
J_Dumont
1400 Views, 2 Replies

iLogic to set Sheet Metal style to known component

I would like to be able to change the Sheet Metal Style of a component from an assembly. I have seen other posts that are similar that will change all components in an assembly but I could use some help with changing an individual component. The user does not need to select the component.

 

Here's what I have so far.

 

SyntaxEditor Code Snippet

Dim compOcc = Component.InventorComponent("Table Top")
Dim SMStyle As String
SMStyle=SheetMetalStyle
compOcc.ComponentDefinition.SheetMetalStyles.Item(SMStyle).Activate

 

Any help would be greatly appreciated.

2 REPLIES 2
Message 2 of 3
MechMachineMan
in reply to: J_Dumont

Things to point out:

1. "Dim" and "As" should both always appear in the same line.

2. Using an "=" on the same line as "Dim" is a "bad practice for beginners", but is doable as long as you still have the 'as' and the type. The below version would be fine:

Dim SMStyleName As String = "1"

3. If you are using a string inside of a variable (ie; a name), you need quotes.

4. Your component name needs the colon portion on it as well, if that's how it's shown in the browser.

5. "ComponentDefinition" isn't available to the ComponentOccurrence Object, but "Definition" is.

 

 

Here is the multiple line you were using, but corrected:

name of component changed: 'Part1:1'

name of NEW style that I was setting it to: '1'

 

Dim compOcc As ComponentOccurrence
compOcc = Component.InventorComponent("Part1:1")

Dim SMStyleName As String
SMStyleName = "1"

compOcc.Definition.SheetMetalStyles.Item(SMStyleName).Activate

here is a single line version, which is probably better for readability if you are putting this into a rule with a lot of other lines:

Just make sure to swap out the wording in quotes to match your needs.

 

Component.InventorComponent("Part1:1").Definition.SheetMetalStyles.Item("Default").Activate

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 3
J_Dumont
in reply to: MechMachineMan

Thank you so much, works perfectly.

I especially like the single line version!!!!!!!


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

Post to forums  

Technology Administrators


Autodesk Design & Make Report