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 isComponentActive / ReplaceComponent

1 REPLY 1
Reply
Message 1 of 2
Anonymous
305 Views, 1 Reply

iLogic isComponentActive / ReplaceComponent

Soz not sure where exactly to post this,

Hey, I can't release the part im working on, but ill try and explain my issue, else I will make mock up to represent it.

im effectively working on replacing components that fit into a certain hole pattern, each of these "plug" components have the same iMates within them. The replace component command through inventor UI works fine, but im trying to automate this through iLogic.

I have an excel spreadsheet with a value called Plug Type, which the User can choose from 7 pre-determined Plugs. then names of these parts are : in the excel u basically choose 1-7 and a linked parameter plug_type is linked in the sub-assembly.
Plug 1.ipt
Plug 2.ipt
Plug 3.ipt etc

And so in the subassembly i attempted to use iLogic as follows :

if Component.IsActive("Plug Type 1:1") = true then

if plug_type = 1 then
else
Component.Replace("Plug Type 1:1", "Plug Type " & plug_type & ".ipt", True)
end if


elseif Component.IsActive("Plug Type 2:1") then

if plug_type = 2 then
else
Component.Replace("Plug Type 2:1", "Plug Type " & plug_type & ".ipt", True)
end if

..........and so on

end if

it works fine if plug type 1 is in the sub assembly, and the option is one of the other plugs( it then replaces the component fine), but if any other one is in there, it errors when its looking to see if Plug Type 1:1 is active.

Is there another way of structuring this? I've only just started looking at iLogic, but i know using the API I could iterate through all the brower nodes for Plug Type, then cut the string to find out which number is active on the end, but im trying to stay away from VBA for now.

Thanks

Harry
1 REPLY 1
Message 2 of 2
MjDeck
in reply to: Anonymous

You should be able to avoid using Component.IsActive, unless you want to suppress the plug under certain conditions. And you can avoid using the
if plug_type = ...
statements.

The trick is to rename your plug component in the assembly model tree. Rename it to something like "Plug:1" instead of "Plug Type 1:1". Then the name will be fixed. It will not change when you replace it, and iLogic can always find it. (But one disadvantage is that you can't see what type is currently being used just by looking at the name.)

Once you rename it, you only need one line of code to replace it:

Component.Replace("Plug:1", "Plug Type " & plug_type & ".ipt", True)


Mike

Mike Deck
Software Developer
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report