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-Rebuild part sub-assembly-regen all rules,rebuild,update from form button

14 REPLIES 14
Reply
Message 1 of 15
CCarreiras
5492 Views, 14 Replies

iLogic-Rebuild part sub-assembly-regen all rules,rebuild,update from form button

Hi!!

 

I’m beginning to do some work using iLogic.

For now , most of the works runs well, but there is some little things to work 100%.

I will put here some cases. I hope someone help with this.

I think these are things that going to help lots of people.

 

Thanks in advance.

 

Case:

I have an assembly (A) and within, i have a sub assembly (B).

The sub assembly’sare driven for the assembly parameters and works well.

 

The problem is;

I have a part (C) in the subassembly (B) that needs “rebuild all” every time I change the parameter’s values, if not, this part stays with a problem to do an extrusion. The part doesn’t need change the geometry, only the size, so I think this problem has nothing to do with the iLogic issues, it simply need to do the rebuild after changing size.

(I find that, when we change parameters, the operations between  unfold/refold need always “rebuild all” the part to operate correctly the changes, I think its because doesn’t regenerate the  sketch from the unfold plane for the refold plane… this is true?!)

 

Question 1:

Its possible to call this part (C) (of the subassembly) to do the “rebuild all” from a rule in the top assembly (A)? It was nice if we can call this “rebuild all” from a form button.

 

Question 2:

Its possible to do a rule in the end of all to do the “rebuild all” and “update all”
automatically, or instead, from a form button?

 

Question 3:

Its possible to have a rule to do “regenerate all Rulles” in a form button?

 

Hope someone helps me, because its only the last things that I need to have a nice work.

 

Im using:
INV PRO 2012 SP1 and Win7

CCarreiras

EESignature

14 REPLIES 14
Message 2 of 15
MjDeck
in reply to: CCarreiras

If you have a rule in part (C), and that rule runs when you change parameters, then you should be able to get the part to rebuild by adding these lines to the end of that rule:

RuleParametersOutput()
ThisDoc.Document.Rebuild()

 

See the attached files.  One of them contains a rule to do a Rebuild All in an assembly.  The other one will Regenerate All Rules.  These files can be used as external rules.  You can add buttons on an iLogic form to run these rules.


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 15
CCarreiras
in reply to: MjDeck

Thanks.

I 'll try this and then i say something.

Regards.

CCarreiras

EESignature

Message 4 of 15
feldwill
in reply to: MjDeck

Mike, can you run your instructions step by step again.

 

II think I have the same problem.  I have main assembly built from machine and a base. Machine is iAssembly and rebuilds fine.  Base is iLogic and doesn't want to rebuild even though I change parameters in the Main (Machine+Base) assembly.

 

Tell me where that code goes (Machine, Base, or Machine+Base Assemblies?), and is it iLogic or Macros.

 

Best Regards

William

Message 5 of 15
swordmaster
in reply to: MjDeck

Mike,

Tried to create a external rule using  your regenerate all rules code

I am getting a "unspecified error"

problem seems to lie in line 1

will this work with Inventor 2009 ilogic version?

Inventor 2010 Certified Professional
Message 6 of 15

Hi 

Message 7 of 15
jdkriek
in reply to: xiaodong_liang

The code is working in 2011-2014 with no errors for me.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 8 of 15

Do you have a line that can be added after the "AssemblyRebuildAllCmd" that can be used on a iPart or iAssaembly, that generate all the configurations, running from an External Rule?

 

Every time you change something in the table, regen all, and Generate parts is time consuming. Thanks. 

Message 9 of 15
J.Tofts
in reply to: CCarreiras

Hi

Try this, in your top level GA create a rule in the rule environment expand doc enter the update when done rule. close edit rule.

you should have this under every rule you have written so the doc's update.

In the top GA right click the top text line you should get run all rules option, this will filter down through all assemblies and parts and everything should re configure itself

if not run the run all rules again and all should be good .

If you have a complex model with lots of rules its a lot to process so run x2 works for me. Hope this helps

 

Message 10 of 15
fridtjofZM5ME
in reply to: MjDeck

@MjDeck Is there a ThatDoc.Document.Rebuild() command of some sort in iLogic? I'd like to automate hitting the "Rebuild all"-button for one specific sub-assembly component from the rule in the main assembly.

Message 11 of 15
MjDeck
in reply to: fridtjofZM5ME

@fridtjofZM5ME , please change the subassembly name in the following code and try it.

Dim subassemComponent = Component.InventorComponent("SubassemX:1")
Dim subAssemDoc As AssemblyDocument = subassemComponent.Definition.Document
subAssemDoc.Rebuild

If that isn't sufficient, you could also use the Document.AllReferencedDocuments property to get the parts under the subassembly and rebuild them.


Mike Deck
Software Developer
Autodesk, Inc.

Message 12 of 15
fridtjofZM5ME
in reply to: MjDeck

@MjDeckThank you, I'll try this.

 

Btw, could you direct me to the part of the iLogic documentation that explains the syntax of these three lines of code, which elements does what etc? I'd like to better understand what I'm actually doing as I'm just learning to use iLogic (by the seat of my pants no less), and I have little to no prior experience with code writing. I see that the suggestions to solutions to the various problems I post to the forum relating to this very often are quite similar to your suggestion here.

 

My comprehension of the "Dim" command is currently limited to typecasting numeric variables to use them mathematically and then write them to parameters to manipulate geometry, basically just giving the elements of the algebra shorter and more convenient names to write in the code. Transfering that over to this I get that we're defining something called "subassemComponent" as the specific sub-assy in question, referencing it as a component in the context of the main assembly which the rule exists in. Then we define "subAssemDoc" as a label for an assembly document. Then comes the part I don't understand; "subassemComponent.Definition.Document". How does that work, and how do I know how and where to use it?

Message 13 of 15
MjDeck
in reply to: fridtjofZM5ME

iLogic uses the Visual Basic language. And the Inventor API can be used in iLogic rules. In this rule, only the InventorComponent line is specific to iLogic.

In the Inventor API there is a Rebuild function, and it's available only on a Document object. So the idea here is to get the Document object from a specific subassembly. Then run Rebuild on it.

As you said, Dim is used to define variables. Here's a discussion of the history of the keyword.


The first line uses the Component.InventorComponent function. That's a quick way to get a single ComponentOccurrence by name.
The second line gets the Definition property of that component occurrence. If you have more than one occurrence of the same part or subassembly, the Definition will be the same for all occurrences. Since this is a subassembly, the definition will be an AssemblyComponentDefinition.
Then we get the Document property from that definition object. Since this is an assembly, the document will be an AssemblyDocument.

In general, methods (functions) and properties in the API are spread out over different objects. Many of the objects correspond to things that you can see in the UI. To find objects that can be reached from object A, look at the properties (and sometimes methods) of object A. You might have to continue down the chain to find something : e.g. B is a property of A and C is a property of B.



Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 15
fridtjofZM5ME
in reply to: MjDeck

@MjDeck Thanks for clarifying. As the only engineer at my workplace, and with a mere four years of experice, I'd be lost without this forum.

 

After a day of trial and error I got this little piece of code to do what I intended, based on your advice earlier:

	Dim subassemComponent = Component.InventorComponent("SK5-1 fl. iLogic_GD:1") 'the subassembly whose components are to be rebuilt
	Dim subAssemDoc As AssemblyDocument = subassemComponent.Definition.Document
	For Each Document In subAssemDoc.AllReferencedDocuments
		Document.rebuild
	Next

so I guess it's coming along at least. What struck me as the greatest challenge was to figure out where the alternative "Document.AllReferencedDocuments" part was supposed to go. As I understand now the "subAssemDoc" and "Document" here are, respectively, specific and general versions of the same type of entity where "Document" in the for each loop references all documents found within the boundry of the "in" argument, while the "subAssemDoc" is the specific sub-assembly I've defined it to be. They're both documents and thus their methods are the same, which I didn't know until the end of last Friday.

 

Whenever I try to figure out where I'm allowed to use a certain method, such as "rebuild" or I just have a keyword describing what I'm trying to do, I try to find examples of context within the Inventor help page (that you've linked to in your answer to my questions) to figure out how to do it. Is there an easy way to search that help page while limiting the results to the ones found withing the iLogic API section? I'm basically trying to search the appendix of the iLogic part without having to sift through everything else, but at first glance it doesn't appear to be a suitable filter I can use on the results. I might have missed it though.

 

 

Message 15 of 15
MjDeck
in reply to: fridtjofZM5ME

To search the help, you can use the single help file that's included in the Inventor install on your computer. This is easier than the online help.
To get to it, use the Help dropdown and navigate to Programming/API Help:
Programming API Help.png


You can also find this help file in Windows File Explorer and add a shortcut to it. The file should be here:
C:\Users\Public\Documents\Autodesk\Inventor 2022\Local Help\admapi_26_0.chm
or

C:\Users\Public\Documents\Autodesk\Inventor 2021\Local Help\admapi_25_0.chm

or a similar name for other versions.


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