Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Run ilogic rule to all part in the assembly

zaidi_drafter
Explorer

Run ilogic rule to all part in the assembly

zaidi_drafter
Explorer
Explorer

Hi,

 

I have one question how to run ilogic rule to all part in assembly? Mean when your run the rule in assembly environment the rule will automatically go to each part in the assembly. not need to open one by one for run the rule.

Any update very appreciated.

 

Regards

Zaidi

0 Likes
Reply
4,017 Views
31 Replies
Replies (31)

MechMachineMan
Advisor
Advisor

Basic reading and googling skills get you a long way.


shakeNbake444 wrote:

 

Doing it exactly how you shown I get:

Error on Line 11 : 'oSubOccurrence1' is not declared. It may be inaccessible due to its protection level.

 

So if i try to declare it with the following code:

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = ThisDoc.Document.ComponentDefinition.Occurrences

iLogicVb.RunRule("DescriptionEditor")

Dim oSubOccurrence1 As ComponentOccurrence
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAssyOccurrences
    If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
          iLogicVb.RunExternalRule("DescriptionEditor")
    End If
Next

 


 

From a dictionary:

 

"declare: openly or formally asserted or announced."

 

Hmmm. So based off the definition given above, and using linguistic skills, it's saying "I don't know what SubOccurrence1 is".

 

Now if we look at the code for the places that occurs, we see it's given a type with this line:

 

Dim oSubOccurrence1 As ComponentOccurrence

K. That's all cool. Variable is explicitly declared (given a type). Maybe the error statement is a bit of a misnomer. But it still implies the issue is with SubOccurrence1.

 

The next occurrence of SubOccurrence1 is:

 

If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

Hmm. Interesting. We are accessing a property/method of suboccurrence1, but do we know what it is/where it came from? NOPE!

 

Just like in english, if I'm talking to a group of people and say "You, grab that phone!", no one would have a clue of who I am talking to unless I somehow indicate who. Same thing applies in programming. SubOccurrence1 is the 'same' as "you"; it's obviously a thing, but we have no clue of who it is.

 

How do we fix it? We tell it who SubOccurrence one is.

 

So if in english, I say

"Each Person In the crowd, Go Touch that phone"

or in pseudocode:

For Each PERSON in CROWD
    Person.TouchThePhone
Next PERSON

we know that we will go through every person. The translation from that into this situation is:

 

For Each oOccurrence In oAssyOccurrences
    If oOccurrence.DefinitionDocumentType ........
Next

  OR

For Each oSubOccurrence1 In oAssyOccurrences
    If oSubOccurrence1.DefinitionDocumentType ........
Next

 

Again, a little bit of reading and a little bit of learning will get you a long way.....


--------------------------------------
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
0 Likes

tdant
Collaborator
Collaborator

Here's a condensed rule that should do the trick. Replace the other two faulty external rules with it, and trigger it on save.

 

Sub Main()
    Dim TopDoc As Document
    TopDoc = ThisApplication.ActiveDocument
    
    Dim SubOcc As ComponentOccurrence
    
    If TopDoc.DocumentType = kAssemblyDocumentObject Then
        Call ChangeDescription(TopDoc.ComponentDefinition)
        For Each SubOcc In TopDoc.ComponentDefinition.Occurrences
            Call ChangeDescription(SubOcc.Definition)
        Next
    Else
        Call ChangeDescription(TopDoc.ComponentDefinition)
    End If
End Sub

Sub ChangeDescription(Definition As ComponentDefinition)
    Dim OccDoc As Document
    OccDoc = Definition.Document
    
    Dim PropSets As PropertySets
    PropSets = OccDoc.PropertySets
    
    Dim DProps As PropertySet
    DProps = PropSets.Item("Design Tracking Properties")
    
    Dim PartNumber As Inventor.Property
    PartNumber = DProps.Item("Part Number")
    
    Dim PartDesc As Inventor.Property
    PartDesc = DProps.Item("Description")
    
    PartDesc.Value = PartNumber.Value
    PartNumber.Value = ""
End Sub

Anonymous
Not applicable

Bingo! thanks for your help and patience.

0 Likes

tdant
Collaborator
Collaborator

Sure thing. I'm not a pro either, so thanks for bearing with my typos and all.

 

Also, ignore MechMan. He's really smart and capable, but smarmy and grumpy sometimes.

0 Likes

MechMachineMan
Advisor
Advisor

@tdant wrote:

Sure thing. I'm not a pro either, so thanks for bearing with my typos and all.

 

Also, ignore MechMan. He's really smart and capable, but smarmy and grumpy sometimes.


 

Smiley LOL Nah. I just don't sugar coat things, and I think it's a pretty fair basic expectation that people at least TRY using their brains or other resources on the internet before asking for something for nothing.

 

You'll notice I don't often be snarky without also offering a clear "next step" for the user, and without looking to verify that the next step I offer isn't a fine solution.

 

Give a man a fish and he'll eat for a day... then he'll demand you feed him for the rest of his life and you'll soon find you don't have time to spread the love and offer help to anyone else.

 

Edit: Winning formula from one of the other very popular websites:

    - https://stackoverflow.com/help/how-to-ask

 

    - Note the first step: Search and Research.


--------------------------------------
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
0 Likes

Anonymous
Not applicable

I took a lot to not fire back something equally as rude.

 

There's no value in cutting people down with belittling comments simply because they don't share the same knowledge as you. I've been in this business long enough to realize the people who do that are stagnant in their professional lives while the people that are willing to help with positive attitudes tend to be the leaders. I don't need google to tell me what declare means. I've programmed before, just not in this language. I've just started messing around with it just this week. And you missed in the one post that I did in fact try to declare the variable and tried your suggestion - also didn't work. There are more constructive ways to give guidance than being smug and sarcastic on a message board :winking_face:

bradeneuropeArthur
Mentor
Mentor
Hi,

My general remark in this is:
Use the API and start writing your own add in.
It is easier and has more functionality!
On the beginning you will think it is not easy.
Afterwards you will see all the benefits of it using add ins an not I-logic.

If help is needed or if you are interested please let me know.

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

cadman777
Advisor
Advisor

Hey Mech,

 

I have to say, I read your last post with interest. You go on and on about an analogy that makes absolutely not sense to me b/c I don't know the meaning of the words in the iLogic code. It would be like me making an analogy on commercial law using Chinese or Arabic words to show you. Would you get it?

 

In order to understand this stuff, you need to know the definitions of ALL the words AND the syntax of how they work together. That's how languages work, except these are MAN-MADE tech lingos. On top of that, you have to have a REALLY GOOD MEMORY for WORDS. Not everybody can do that or has that. It's your gift, but not mine. Needless to say, I didn't get anything out of what you said.

 

This is just one of a myriad of forum posts I've read over the past few days. Actually, I just spent the past 30 some odd hours just trying to get up to speed on ilogic to see if I could write some SIMPLE ROUTINES like I used to write for AutoCAD using AutoLISP, scripts and DIESEL. But nothing doing. TOO DAMNED COMPLICATED (you need to know a little VB too!).

 

Have you ever learned a foreign language? If so, have you tried learning 2 at the same time? I knew a guy from Switzerland when I studied overseas (in my 20's ... a LONG time ago!). He was a language GENIUS. He used to work w/me on my Hebrew and Arabic. But man was I in the stone ages compared to him, and I never could get the knack of it. He knew how to speak and write TWENTY TWO languages when I met him! And he was learning Hebrew and Arabic at the same time (similar languages) on top of that! And b/c he had some Korean friends, he was also learning Korean at the same time. Geeez! But that ain't me, dude. And I doubt it's you. Get my point?

 

In case not, check out this video and see if you know what this guy's analogy is talking about. I sure don't! And I've used torque wrenches for decades, and have been wrenching and diagnosing cars and trucks for over 40 years!

 

Anyways, thanx for your explanation. I'm sure it goes a long WITH THE RIGHT PEOPLE ... that is, people who THINK LIKE YOU. But that ain't me baby!

 

Cheers ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes

MechMachineMan
Advisor
Advisor

Hey dude,

 

It's cool to hear your sentiment and all, but reviving a 1.5 yr old post for some remark irrelevant to the problem-at-hand is at the same productivity level as my snarky remarks back in the day. Please try and keep on topic, and know I will continue to avoid responding to questions in a less-than-positive fashion.

 

For now, remember to stay on topic so that we can help those trying to solve problems in a quick, clean fashion.

 

Anyways.... I hope you find solutions to the Autodesk Inventor related problems you're likely here searching for.

 

Cheers,


--------------------------------------
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
0 Likes

cadman777
Advisor
Advisor

Hey guy, thanx for getting back to me.

 

The reason I 'revived' an old post is b/c it's one of the posts I read based on being told to read it in another post, to try to find a piece of the solution I'm trying to accomplish BEFORE coming in here and asking for help.

 

There's a lotta frustration behind wasting 30 some odd hours trying to learn the basics of a process that looks to me like it takes years to learn. I have one full shelf of books I used to use when writing AutoLISP and DIESEL. Some are lessons on learning how to write 'code', and others are REFERENCE MANUALS an inch and a half think each. I have not been able to find any such reference manuals for iLogic. That means ALL the words are meaningless to me. End result: I just want to be able to write some simple MACROS (not programs, but MACROS like you can do in the AutoCAD with SCRIPTS) without having to learn a programming language.

 

Any ideas how I can learn that in a short period of time?

 

Any idea where I can get those REFERENCE BOOKS on the subject for use when learning it?

 

Thanx ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes

MechMachineMan
Advisor
Advisor
Samples, API documentation from the online help, etc.

Not aware of any easy straightforward guides from level 0 though.

My signature should have some good links of samples.

--------------------------------------
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
0 Likes

cadman777
Advisor
Advisor

OK, thanx.

I finally found the Reference 'books' on the Autodesk Inventor web site.

So that helps a lot.

I finally found a few simple YouTube videos on iLogic basics.

Apparently the 'industry' makes you 'pay your dues' if you want to work outside of their profit-churning commerce channels.

Mostly my problem learning this stuff is all the nit-picky questions I have about the details of what I SEE in the code and how the code FLOWS.

Hopefully in a few days I'll be writing my own and modifying others.

Remember "Hot Tip Harry"?
That was one of the great resources I used to learn AutoLISP, besides all the articles I cut out of Cadalyst magazine and a couple good books.

This electronic age is a clusterf**k of information, and it surely ain't sorted out for 'beginners' and LINEAR THINKERS like me.

Cheers ...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes