Link parameter from one part to another part

Link parameter from one part to another part

cadman777
Advisor Advisor
4,684 Views
71 Replies
Message 1 of 72

Link parameter from one part to another part

cadman777
Advisor
Advisor

Hi All,

Does anybody have any simple rule that will take a Parameter from one part and push it into another part and format it the way you want it to be formatted?

Here's what I'm trying to do:

1. All driving iProperties and Parameters are located in the master sketch (ipt), which is derived into all manually made parts, but not derived into any of the FrameGenerator parts.

2. I need certain iProperties and Parameters linked from the master sketch to certain FG parts.

3. I also need to format the Parameters.

4. And then I need to copy the resulting Parameter value into another iProperty in that part file.

I can do #4, but can't figure out how to do #1-#3.

I figured the way to do it is to open the master sketch and run the rules from it on the parts I select through a file dialogue box. Or run them using a rule that calls rules and runs them (I've done that before).

Any help is very much appreciated, since I'm out of my depth every time I try to make a rule!

... 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
4,685 Views
71 Replies
Replies (71)
Message 21 of 72

cadman777
Advisor
Advisor

Appreciate the gesture. Let's see if I can unscramble my head and simplify it after all the gobbledy-**** code attempts.

There's a dataset above with a revised master part below the first posted zip file.

 

I put all the parameters into a master part ("_Wireframe...") where they're easy to compile and edit. I don't want to use Excel as an external data source due to down-stream problems that nearly always develop later in a project.

 

1. There is a Parameter in the master part ("_Wireframe...ipt") that I want LINKED to all the files in the FrameGenerator folder. By "LINKED" I mean the way you LINK to external files when inside the Parameter dialog. I want this so if the Parameter name or value changes in the master part (source) file, it will also update in the target part file.

2. Each Parameter is specific to the type of part in the FG folder (different rule for different parts).

3. The rule has to allow the user to pick the files it'll process via a FileDialog, or all the files must be opened and then the rule run on each one (I've done the latter using iProperties, but can't get it to work with Parameters.)

4. Then I want to either 'inject' a simple rule into each file, I already have a rule that works as desired), or call an External rule to run on each file. The rule that runs on each file is dependent on the type of part the file is, so there will  be different rules for different types of parts. I've used an External iLogic rule in the past to run another External rule on open files, so I can do that already.

5. I want the rule that runs inside each part to be Triggered by a 'Before Save' event.

6. Then update the part so the changes take effect.

I think that's it.

 

Overall, what I'm trying to do is create a calculation of all parts in the BOM/PartsList using a PRICE listed in the master file. I get that Price by going on the Internet and pricing each part that's in my BOM, and making that price as a 'ul' Parameter which I can use to do calculations. So the rule that's run inside each part calculates the total cost of the part based on the master file PricePerUnit and a formula that multiplies that Parameter with the critical dimensions if the part. Like I said, I already wrote a simple calculation rule for these parts. I just need to inject it into each file, or run it from an External rule on each file.

 

The dataset I provided is a very simple example of a mix of parts for this type of thing.


Thanx for helping...

... 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
Message 22 of 72

NachoShaw
Advisor
Advisor

Hi

 

i sort of feel that you are over thinking this. You can achieve the same results by having a rule in the assembly that updates the parts based on the FG type by simply looping through the references, checking its type by condition and adding / editing a parameter based on its name from the master part. The rule will be fired from the assembly on any change and its guaranteed to down stream to all referenced parts. you wouldnt be able to 'inject' the code to each part and with the code being at part level, your results are dependant on the part having the code.

 

Personally i would want as little amount of rules as possible and its so much easier accessing properties & parameters from the assembly level. If that works, i can simplify what i have written out to show you how that would work. Just need a list of criteria that establishes the different types of FG parts

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 23 of 72

A.Acheson
Mentor
Mentor

I agree with @NachoShaw assessment and would add that the custom iProperties can be used alone for the calculation avoiding the parameters which I think over complicate things lots of back and forth through that parameter box. And also when changing members through frame generator all info in the parts is lost so best not change any variables manually in the member files. 

 

  1. Variables to be injected in are cost/ft, just type them at the top of the rule for now don't need to be in a  parameter, one per each group of parts
  2. Create the filter by code to target the same group of parts (stock number/part number) what the material will be purchased with, I didn't see a stock number that could target the  width and thickness of a board independent of the length. Example  below the part number hides all of the individual cut lengths.

AAcheson_0-1631651192909.png

 

3. Ensure length parameter is consistent for every part

4. Multiply length parameter x cost/ft and place into cost per item iProperty or wherever you want to place it. 

You can get away with only one iProperty actually being in the part cost per item

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 24 of 72

cadman777
Advisor
Advisor

Your suggestion sounds good. I thought of it too, but don't know how to write the code. I tried. Let's face it, that's intermediate to advanced coding. How can I learn to do it?

 

What I don't understand is, how is it so difficult to establish a link between 2 parts using iLogic? It takes 6 mouse clicks: Parameters dialog>Link>select file>select parameter/s>OK>Done.

 

Doing it your way, I can Link all the parameters that are in the master file to the assembly, and then use them from there. But I'd have to have a rule for each type of part. I've done that before using the 'Category' iProperty to separate the parts by category. It could get involved when many kinds of parts exist in a FG assembly. I already have code to do the calculation. It's in the parts that are registering 'Cost'.

 

There was a time a few months ago when I tried using Public & Private Subs. I wanted to make a rule that had a main running sub and then it would solicit work from private subs to finish the job. I was trying to make it like a structured assembly. But I just didn't know what I was doing, and all the books I read didn't tell me squat. The 'learn by example' method SUCKS for people with a challenged memory and a head full of ideas. And accessing the reference resources to step through from the top of the object model to the bottom is impossible to find. If I could find something like that, I'd be 'sh*tting in high cotton'! So, working between the object mode, the object library and the help definitions (which SUCK!) + examples is not a good way to TRY to learn this clusterf*ck. It's TMI at best.

 

 

... 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
Message 25 of 72

cadman777
Advisor
Advisor

I agree with you. But b/c I don't know how to write code, even though I've tried for going on 3 years, it ain't an option for me. At this point, all I do is try to combine what others have written, except for the most simple kinds of operations using iLogic.

 

1. & 2. I already tried doing that, but can't figure out how to get it run. Th e reason: I don't know the basic things to do when writing code from scratch, and trying to cobble-together other people's code is a clusterf**k (to put it mildly).

 

3. & 4. I already have that part working for a rule inside the part.

 

Like I said, I don't know even the basics on how to write code for Inventor.

If I could learn that, I wouldn't be wasting all our time in here.

But of the 10 resources I've tried to use, none of them make it a learning experience.

It always ends up being MEMORIZE EVERYTHING and pull it from memory what you need  when you need it.

Unfortunately, that's not within my abilities any longer, and it was tough even in my younger days.

 

I'm open to options for learning if someone can give me a good source of teaching info SPECIFIC TO INVENTOR.

... 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
Message 26 of 72

NachoShaw
Advisor
Advisor

Hey

 

To learn how to do it, i would first try not to learn in ilogic. some people swear by it but its more like half coding thatn real coding. To learn, you can access the API (Help, Programmong/API Help). I write in VB.Net for applciations, VBA for any quick testing, iLogic for singular functions that i need like a quick parameter update but even thats a rare case.

 

Linked parameters is actually more like a derived part. in fact, i prefer to derive my parameters vs linked parameters. Somehow i feel it just works better. iLogic is limited to what it can provide. The intellisense only works for iLogic components even though other code structures can be written. It needs to be more intuitive.

 

you wouldnr need a rule for each type of part, you just need a criteria that can be set in Select Case statement. If you want to provide the criteria for your parts, i can write it up for you so that you can see how its structured. I looked at your FG parts and can see that the Stock Number differs. Can you list which parameters would be associated with the Stock number? i can use that as the criteria unless there is something different.

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 27 of 72

NachoShaw
Advisor
Advisor

also, this forum is a great resource as is ModTheMachine

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 28 of 72

cadman777
Advisor
Advisor

Thanks for your quick reply.

 

I agree, SelectCase would be nice, if I could get it to work.

 

What I try to do is get one piece of code to work, and then try another piece to do something else, and then try another and another, and then try to add them together, until I get the whole thing working. But that NEVER works out. So I'm stuck using other people's code (I've gotten pretty good at adapting code that will run). Otherwise, I just write little snippets to do little things and they work well enough. But the real stuff I need to learn how to do I just can't catch on. What I need is 'programmed learning' for Inventor, specifically from someone who thinks like a mechanical engineer, not like an electrical engineer or programmer. Their way of thinking NEVER makes any sense to me. The reason is b/c it's spotty and incomplete. I'm a LINEAR THINKER, so need to learn things 'in order' until they all pile up to the full thing.

 

OK, if Derived Parameters is the best way to go, then that's what I should do. But why have a Parameter LINK in a part if it's useless in programming? Doesn't make any sense...

 

I installed VB.Net 2017 a few months ago to learn more of this stuff, but I never can seem to figure it out. I can't figure out the BASICS. Like I said, I need 'programmed learning', not 'learn by example'. My memory capacity at this point in life is dogshyt. If I can learn how to do snippets of things, and learn how to combine them, and also learn how to follow program flow, and structure a program, then maybe I can learn this. Anyway, I know what I need to learn, but just can't find any resource for learning it.

 

Like i said, I won't use StockNumber to identify which parts belong to which categories. I use 'Category' iProperty and manually input the separate category name via the BOM. I did that already in the assembly. Besides, I use StockNumber already for my MARK in the PartsList. Another way to do it is by part FileName.

 

Here's what I would use:

1. Category as the part identifier.

2. Open the assembly and BOM and look at PartsOnly to see what I mean.

     Also in the assembly is every Parameter derived from the masterfile (ipt sketches).

3. Each part has an iLogic rule in it that calculates the price based on the masterfile Parameters. You can see which Parameters I used for this to identify them in the assembly Linked Parameters list.

 

it's all contained in the attached (updated) dataset.

 

Thanx for helping.

 

 

... 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
Message 29 of 72

cadman777
Advisor
Advisor

I've tried to use code off ModTheMachine, but can't figure out how to adapt it to my needs.

For example:
There's a very nice piece of code that draws 3 view in and idw file.

I understand what he did, but don't know all the boundaries and options for that particular object/method.

So when I tried using another rule that I have which plows through all the parts in an assembly looking for only sheetmetal parts, and adapting it to non-sheetmetal parts, to make 3 views, I couldn't for the life of me figure out how to do it. All the sample code I ever find goes only 1 step into the process. But I needed multiple steps. For example, I needed to move the 3 views around so they didn't overlap. So that code was basically a waste of my time, I'd say THREE DAYS' TIME. So I just up and quit trying b/c I have much more important things to do w/my time than waste it on trying to learn how to program, absent any competent guidance. It's like a blind man trying to learn how to oil paint in color. It's a clusterf*ck matrix of someone else's thought process which you're adapting it to your own.

Like I have said over and over again: I need to learn the BASICS.

... 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
Message 30 of 72

NachoShaw
Advisor
Advisor

ok

 

based on the category, which parameter belongs to which category

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 31 of 72

NachoShaw
Advisor
Advisor

the API is pretty robust, the method of coding within Inventor is a standard programming language (outside of iLogic that is). Once you get into the programming more, you will see that there are structures for each object and similar methods of obtaining your needs. Autodesk cannot cater for every individual hence why there is an API to use. To be fair, programming Inventor vs Solidworks is a breeze 🙂

 

Looping objects requires a iteration-

for i as Integer = 1 to oViews.Count

Next

For Each oView in oViews

Next

 

etc etc

 

a bit of patience goes a long way in coding. the API help files really do provide a lot of good help with great explanations.

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 32 of 72

A.Acheson
Mentor
Mentor

Sounds like this is a topic for another post. And for sure moving any object is not an easy task so I wouldn’t blame you for giving up. I have a library of ditched code and a to do list of that would be nice but no skills yet so move on. I find grabbing one topic that your struggling with and look up as much content as possible on that one topic.

 

One item you  mentioned is objects and options. The API help has the information but can be difficult to navigate the information and relate it to a real example not to mention form a workflow from all the snippets you see. So to access this in the editor you need to declare your objects. It is one of the best things I stumbled across while learning. In ilogic it’s not really needed, but in VBA you can’t go anywhere without it so best learn how to use it to your advantage.


A simple example would be to declare a word as string. Once declared you have access to all the options/functions available to work on that object. Without doing that you would have to just know what words to type to get access to that object (options- the drop down list)  or collection of objects also known as  collections.


Be curious after declaring an object . Place a decimal “.” To get access to its options or open a bracket “(“ and hover the mouse and see what information is being shown in the tool tips. 

Here is some helpful links


Working with a string

https://m.youtube.com/watch?v=SI9hBRA0414

 

https://docs.microsoft.com/en-us/office/vba/language/concepts/getting-started/understanding-objects-...

 

Here is a good link

https://www.codeproject.com/Articles/8825/Object-Oriented-Programming-In-VB-NET

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 33 of 72

cadman777
Advisor
Advisor

Re: "a little patience goes a long way".

A good friend of mine has a saying:

"You can have 20 years of experience, or you can have 1 year 20x."

10 hours of 'trying' to write code is like 1 year 20x.

Patience is not the problem, ignorance is.

 

OK, I'll go back to VB.Net and give it a try again.

It's an ocean of creatures, most of which I'm totally unfamiliar with, and the landscape of which is completely foreign to me. Hopefully one more try will yield some encouraging results. It's the SYNTAX and STRUCTURE of a program that I need guidance on. Basics is what I need.

 

Correct, the multi-view drawing is a different subject for another thread. But if I can figure this stuff out, then I can figure out how to do that too.

 

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
Message 34 of 72

NachoShaw
Advisor
Advisor

I hear you mate i do. Whenever i try to explain coding i say its based on scenarios. Thats what is written. The objects are different but the methods are the same. Typically you are going to construct your object members, do something with them based on criteria and then destroy them. I work mainly in VB.Net which has the advantage of writing classes which is great because i can organise coding much better. also, i can get the class to do what i need with very little calls. With Inventor, most objects are set up the same way-

 

Dim _InvApp As Inventor.Application = MyGlobalApp

'Part Document
Dim pDoc As PartDocument = _InvApp.Documents.Open(MyPath, False)
Dim pDef As PartComponentDefinition = pDoc.Definition

'Assembly Document
Dim aDoc As AssemblyDocument = _InvApp.documents.Open(MyPath, False)
Dim aDef As AssemblyComponentDefinition = aDoc.Definition

'Document
Dim dDoc as Document = _InvApp.Documents.Open(MyPath, False)

       Select Case dDoc.DocumentType
            Case DocumentTypeEnum.kAssemblyDocumentObject
            'do something for an assembly
            Case DocumentTypeEnum.kPartDocumentObject
            ' do something for a part
        End Select

 The API help files have lots of code examples as well as good descriptions. you can find in from the Help button inside Inventor or by browsing to this location C:\Users\Public\Documents\Autodesk\Inventor <version>\Local Help

 

Once you get into it, you'll find it much easier and there are many benefits.

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 35 of 72

cadman777
Advisor
Advisor

OK mate, thanx.

Let's see how it goes.

'I'll be back...'

... 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
Message 36 of 72

A.Acheson
Mentor
Mentor

 

Here is my attempt. I have kept the filtering of the documents very simple for now. Filtering looks at category iProperty then does the math in each category as it finds it. Just paste it in the main assembly as an internal rule.

 

 'https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html
Sub Main 'Added to rule using capture snippet, find the parameter above in the tree then use the paramter window hightlight the name. 'And Right mouse click capture snippet 'PJoist_UL = Parameter("_Wireframe-FB_Link_Parameter1b:1", "Price_per_ft_2x6_board_HD")'Parameter from Master Sketch,'Price of joist per foot PJoist_UL = Price_per_ft_2x6_board_HD'Parameter from Assy,'Price of joist per foot PDecking_UL = Price_per_sq_in_4x8_HD 'Parameter from Assy,'Price of joist per sq in ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get all of the referenced documents. Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments ' Iterate through the list of documents. Dim oRefDoc As Document 'Loop through all referenced documents For Each oRefDoc In oRefDocs Dim oPrice As Double 'Find the part by looking at category in each document using oRefDoc.DisplayName as the document reference If iProperties.Value(oRefDoc.DisplayName, "Summary", "Category") = "Joist" Then Logger.Info("DisplayName: " & oRefDoc.DisplayName)'FileName Dim oG_L As Double oG_L = Parameter(oRefDoc.DisplayName, "G_L") Logger.Info("Length: " & oG_L)'Length 'Price Calculation oPrice = PJoist_UL * (oG_L / 12) ' with G_L in inches, Logger.Info("Price: " & oPrice)'Price 'Apply the pricing to each document If oPrice <> 0 iProperties.Value(oRefDoc.DisplayName,"Project", "Estimated Cost") = oPrice End If 'Find the part by looking at category in each document using oRefDoc.DisplayName as the document reference ElseIf iProperties.Value(oRefDoc.DisplayName, "Summary", "Category") = "Decking" Then Logger.Info("DisplayName: " & oRefDoc.DisplayName)'FileName Dim oLength,oWidth As Double 'oLength = iProperties.Value(oRefDoc.DisplayName, "Custom", "SheetMetalLength")'Given In fractions will fail when declared as double use parameter instead oLength = Parameter(oRefDoc.DisplayName, "SheetMetalLength") Logger.Info("Length: " & oLength)'Length in inches 'oWidth = iProperties.Value(oRefDoc.DisplayName, "Custom", "SheetMetalWidth") oWidth = Parameter(oRefDoc.DisplayName, "SheetMetalWidth") Logger.Info("Width: " & oWidth)'Width in inches oArea = oLength * oWidth Logger.Info("Area: " & oArea)'Area/sqft 'Price Calculation oPrice = PDecking_UL * oArea ' with G_L in inches, Logger.Info("Price: " & oPrice)'Price 'Apply the pricing to each document If oPrice <> 0 iProperties.Value(oRefDoc.DisplayName,"Project", "Estimated Cost") = oPrice End If End If Next End Sub ' Logger.Info("DisplayName: "& oRefDoc.DisplayName)'FileName ' Logger.Info("FullDocumentName: "& oRefDoc.FullDocumentName)'FilePath ' Logger.Info("FullFileName: "& oRefDoc.FullFileName)'FilePath

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 37 of 72

NachoShaw
Advisor
Advisor

Here is my version using a select case on the Category iProperty per document (oRefDoc)

 

Sub Main()

	'set up the active assembly document
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument

	'set up the enumerator to loop through the assembly
	Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments

	'loop through the references (not occurrences so that you only change 1 of each file)
	For Each oRefDoc As Document In oRefDocs

		'get the Category iProperty to use as the condition
		Select Case iProperties.Value(oRefDoc.DisplayName, "Summary", "Category")
			Case "Joist"
					Dim oG_L As Double = Parameter(oRefDoc.DisplayName, "G_L")
					Dim oCost As Double = Price_per_ft_2x6_board_HD * (oG_L / 12)
					
					If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, _
																	"Project", _
																	"Estimated Cost") = oCost

			Case "Decking"
				Dim oLength As Double = Parameter(oRefDoc.DisplayName, "SheetMetalLength")
				Dim oWidth As Double = Parameter(oRefDoc.DisplayName, "SheetMetalWidth")
				Dim oArea As Double = oLength * oWidth
				Dim oCost As Double = Price_per_sq_in_4x8_HD * oArea
				
				If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, _
																	"Project", _
																	"Estimated Cost") = oCost
		End Select
	Next
End Sub

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 38 of 72

cadman777
Advisor
Advisor

@NachoShaw @A.Acheson 

 

Guys, thanx very much for these.

Looks like we have a competition going on!

 

I ran both of them and this is what happens:

 

1. I ran Nacho's as an iLogic rule, and it works on the Decking, but not the Joists. It errors out saying "can't find [shows a FG filename]".

 

2. When running Alan's as an iLogic rule, it errors out with, "Rule compiles error...Error on Line ...: 'Logger is not declared. It may be inaccessible due to its protection level." So then I tried running it as a VBA rule, and it errors out too. So I guess it's an iLogic rule, right?

 

I want to try to figure this out myself, and if I can't, then will ask for help.

That's one way I learn how to do this stuff.

But, I have to go out of town for a couple weeks, so when I'm back I'll work on it.

 

Again, thanx for your help, I really appreciate it.

 

Meanwhile, when I get back I'm going to do that VB.Net course online that you guys linked me to.

I did another one many months ago, but after getting part way into it, my brain got all clogged up with all that info, and without using it, it just 'dumped' into oblivion. Hopefully this little course will help further. The way this stuff 'sticks' is for me to do a hand's on course that's relevant to what I'm doing.

 

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
Message 39 of 72

cadman777
Advisor
Advisor

@A.Acheson 

I commented out the 'Logging' lines and yours ran, but it still errorred out like @NachoShaw's did.

I assume this is what 'Logging' is.

Logging doesn't run in my version of Inventor.

I would like to know how I can use MessageBox.Show() to see any nonString value.

Can you show me how to do that?

 

@NachoShaw 

Since your rule was easier to follow, I tried fixing the error in yours.

I thought that if I could figure out what was wrong in the simpler code, I could do it in the more complex code.

So I added "Footing" and "Post" to the Case list, and ran it, but it didn't work for them either.

It only worked for the Decking like originally.

I thought that maybe the problem was the FG parts.

But since the Footing is a non-FG part, and since it didn't work on the Footing, I concluded it's something else that isn't working. But I can't figure out what it is b/c I don't know what to look for. It's a gigantic SECRET buried somewhere on the Internet, or in a book, or in some expert's mind. But I do think it has to do with the way iLogic identifies the part files in the assembly and then how it turns around and uses that name to process them. So I tried changing the code to get iLogic to see the filename instead of the part name listed in the model tree. But I'm guessing on exactly what words to use to make that happen, which is why it isn't working for me.

 

After wasting 3 more hours on this, I'm stuck (as usual).

Here is why I can't figure this out:

1. I'm a LINEAR THINKER, so I need LINEAR PATHWAYS to LEARN what to do.

   I put that in all caps b/c nobody in here seems to get that.

   All the code developed in here is anything but linear.

2. I started out w/the Object Model poster to look for what I want to use, which in this case is FILENAME.

    But FILENAME isn't in the Object Model poster. I'm guessing that it must be a PROPERTY of the object FILE. The closest thing to it is "Application>FileManager>...FILE".

    But I don't know how to write code to access that.

3. What I try to do is First locate the Object I need (which is a guess most of the time) in the Object Model poster. Then I go to Inventor's VBA Object Reference app. Then I type in the Object that's in the Object Model poster, and a list of objects appears. Then I scroll down through that list and try to find something related to what's happening in the code. Most of the time I have no idea what to pick b/c there are multiple entries that may or may not be relevant, b/c I don't know how these objects work. At that point, I get stuck, almost every time. But if I DO find an object that MAY work, b/c the WORD of it seems to indicate that it will, I then press F1 to see what the Help says. Almost always it doesn't mean squat to me, so I just close that and get angry.

 

Right now, after WASTING another 3 hours, I'm ANGRY.

Where can I find a LINEAR PATHWAY that will STEP ME THROUGH what I want to accomplish?

 

Let me give you an example of what I'm talking about:

 

When I diagnose engine runnability issues, I first look at the bullshyt trouble codes. Unless you know how that particular vehicle's computer system works in detail, you won't have a clue where to start diagnosing BASED ON that bullshyt code. That's how it is MOST of the time. So instead, you go read about it on the internet and see if other people have the same problem. For older cars and trucks you usually find your solution, or at least a clue where to look next. But if you're like me, and you know cars and trucks and have all that info CATEGORIZED in your mind already (b/c of a lifetime of experience), you just need to do one of two things to get started: 1) go to the service manual and look up the CODE PROCEDURE and follow it (which MOST of the time is just more bullshyt), or 2) start testing circuits: components, wires and connections. I absolutely HATE that part b/c sometimes it's very difficult to access things. But either way, it's a LINEAR PROCESS from start to finish, once you locate what you need to test.

 

That is just like coding. You start with an idea (like a vehicle a Trouble Code or 'customer complaint') and figure out where to begin testing. The Code gives you a HINT based on the WORD (P0016, B1220, etc.). But that code doesn't tell you what it means and what's connected to that system. You MUST pay for that SECRET information to know that. So if you don't have the wiring schematics, you're f*cked most of the time. And if you don't know the BASICS, you're wasting your time trying (like with me and VB). But fixing a vehicle is really only a 2 step process: DIAGNOSE and TEST. Same w/coding. The only difference is, I possess the TOOLS to do the troubleshooting and testing on vehicles. But w/Inventor, I STILL don't know which tools to use OR how to use them. And IF I needed a LINEAR PATHWAY, I can't find it w/Inventor. Sometimes (like with Honda and Ford) the linear pathway is the easiest method of troubleshooting. Just get the book, look up the Code, and follow the steps. MOST other cars and trucks are a clusterf*ck of bullshyt computer gobledygook, and their linear troubleshooting pathway isn't effective most of the time. So most times I resort to the DVM and a lab scope. But w/iLogic and VB I have NO IDEA what to use to get to where I need to get. It's a GIGANTIC CLUSTERF*CK of DISORGANIZED and SCATTERED information designed to be used by those 'in the know'. Like I've said many times in the past, this is no different from trying to navigate the court systems of government. If you aren't a trained lawyer, with a paralegal and a bunch of other 'connections', then good luck. You'll get your one bite at the apple, but don't be surprised if it's full of worms and pesticides that'll kill you. And even if you manage to make a good showing in the courts like Clif High did recently, you hardly stand a chance against big money or government, b/c the system is RIGGED against you for them to always win.

 

When I attempt to learn how to code, that is what comes to mind at my points of failure and frustration. I know I'm right. Incidentally, my previous rant above about VISUAL PROGRAMMING like in RHINO3D, I discovered from a friend at Berkley that the visual programming language has been around since the mid 80's. All the more reason to shyt on Auodesk for saddling us w/this this unmanageable burden and POS they call their MACRO LANGUAGE.

 

Incidentally, here's a screen shot of the error I get on from macros:

 

cadman777_0-1631897013593.jpeg

Oh yes, and I tried converting the Inventor iLogic macro into Inventor VBA, but got stuck at 'Parameter' b/c it said it "Compile error: Sub or function not defined". I figured that maybe I could see more of what's going on in the VBA editor, even though I still don't understand most of what I'm looking at or now to use that tool (even though I studied on it for many hours). So I tried figuring out what to change but couldn't, b/c I don't know what I'm doing. AND, as always, I have NO IDEA where to look for the answer. The amount of hunting I do on the internet and in other resources just to find ONE G.D. SOLUTION among the MYRIAD of G.D. PROBLEMS in coding makes this learning process TORTURE. Here's my attempt at converting Inventor iLogic to VBA:

 

' This rule calculates the total weight of the entire assembly
' Here is my (NachitoMax) version using a select case on the Category iProperty per document (oRefDoc)
 
Sub Main()

    'set up the active assembly document
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument

    'set up the enumerator to loop through the assembly
    Dim oRefDocs As DocumentsEnumerator
    Set oRefDocs = oDoc.AllReferencedDocuments

    'loop through the references (not occurrences so that you only change 1 of each file)
    Dim oRefDoc As Document
    For Each oRefDoc In oRefDocs

        'get the Category iProperty to use as the condition
        Select Case iProperties.Value(oRefDoc.DisplayName, "Summary", "Category")

            Case "Footing"
                Dim oVol As Double
                Set oVol = Parameter(oRefDoc.DisplayName, "Volume")
                Dim oCost As Double
                Set oCost = Price_per_cf_concrete_HD * (oVol / 12 ^ 3)

                If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, "Project", "Estimated Cost") = oCost

            Case "Post"
                Dim oG_L As Double
                Set oG_L = Parameter(oRefDoc.DisplayName, "G_L")
                Dim oCost As Double
                Set oCost = Price_per_ft_4x4_post_HD * (oG_L / 12)
                
                If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, "Project", "Estimated Cost") = oCost

            Case "Joist"
                Dim oG_L As Double
                Set oG_L = Parameter(oRefDoc.DisplayName, "G_L")
                Dim oCost As Double
                Set oCost = Price_per_ft_2x6_board_HD * (oG_L / 12)
                
                If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, "Project", "Estimated Cost") = oCost

            Case "Decking"
                Dim oLength As Double
                Set oLength = Parameter(oRefDoc.DisplayName, "SheetMetalLength")
                Dim oWidth As Double
                Set oWidth = Parameter(oRefDoc.DisplayName, "SheetMetalWidth")
                Dim oArea As Double
                Set oArea = oLength * oWidth
                Dim oCost As Double
                Set oCost = Price_per_sq_in_4x8_HD * oArea
                
                If Not oCost = 0 Then iProperties.Value(oRefDoc.DisplayName, "Project", "Estimated Cost") = oCost
        End Select
    Next
End Sub

 

Incidentally, I got one of my degrees in TEACHING, and can honestly say that this is not how people should learn. FAR FROM IT!

... 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
Message 40 of 72

NachoShaw
Advisor
Advisor

Mine works, here is what i did with your files

 

Assembly

link the parameters from the Base Model so that any changes are available at assembly level

 

FG parts / other parts

removed the linked parameters because you cant edit them locally which is probably why you are getting some errors

 

Logging

you need to add an iLogic log, but not in iLogic! i know, doesnt make sense but then again nor does iLogic 🤔

click the +, add iLogic Log

log.gif

 

MessageBox examples

Dim TestString As String = "This is a test"
MsgBox(TestString)
MsgBox("This is a test")

If Msgbox(TestString) = MsgBoxResult.Ok Then
    'you can do something here conditionally
End If

 

Document Path (the active document)

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim path as string = oDoc.FullFileName

 

Document Path (for an occurrence - Assembly component)

Dim MyPath As String = "C:/MyPath/MyAssy.iam"
Dim oDoc As AssemblyDocument = CType(_InvApp.Documents.Open(MyPath, False), AssemblyDocument)
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

Dim oOcc As ComponentOccurrence = oDef.Occurrences.Item(1)
Dim pDoc As Document = CType(oOcc.Definition.Document, Document)
Dim oPath As String = CType(pDoc.FullFileName, String)

 

Coding isnt easy but powerful when understood. learning to code with iLogic would be harder because there is limited intellisense vs VBA & VB.Net, some examples:

 

iLogic (not the AssemblyDocument not showing in the intellisense). Notice that MyPath isnt shown in the intellisense even though its a valid object

code1.gif

 

VBA (not how the structure is split into 2 parts, Dim and then Set). Also notice that MyPath isnt shown in the intellisense either even though its a valid object

code2.gif

 

VB.Net ignore the errors, i added to the base of my code and it already exists)

code3.gif

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes