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.
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
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
Can't find what you're looking for? Ask the community or share your knowledge.