Link parameter from one part to another part

Link parameter from one part to another part

cadman777
Advisor Advisor
4,652 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,653 Views
71 Replies
Replies (71)
Message 41 of 72

cadman777
Advisor
Advisor

Thanx.

 

I already did this before posting my message:

 

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

 

My version of Inventor doesn't have Logging, but I can use the 'Debugger' app:

 

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

 

 

I already know how to use MessageBox.Show() to see a String. But I want to use it in iLogic to show other values like in the Watch box in VBA. Can that be done?

 

Yes, I know how to get the FullFileName and the Path. But I don't know how to make your oRefDoc get the FullFileName and use it instead of the DisplayName. I wanted to see if changing the way the rule identifies each file from ModelTree to FileName will fix the problem "file not found".

 

My version of iLogic doesn't have intellisense, but my VB Studio editor does. But it's hard for me to keep switching between the two, so if I can learn how to use the VB Studio editor, that would be perfect. I think my biggest problem is, I BELIEVED Autodesk's LIES about iLogic and started there. Then after I got BRAINWASHED in a little iLogic, I learned/heard that Inventor VBA is much better b/c you can see what's going on. So I switched. But I could never figure out how to use VBA so went back to iLogic. But then I watched one of Brian Ekins' tutorials and followed along with it in VB Studio and was SOLD on it. But after that I still didn't know how to code. So I'm always going back and forth and round and round with 3 different editors b/c most of my rules are in iLogic, and I try to cut and paste parts of each together to accomplish other tasks, unsuccessfully I might add. So my brain is FRIED on all clusterf*ck of learning. What I need is lessons on how to combine what to make my code. Incidentally, I realize this is powerful IF one can learn it, which is why I've been trying on and off for going on 3 years.

 

Incidentally, nice gif's!

What app did you use to make them?

... 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 42 of 72

A.Acheson
Mentor
Mentor

Yes the log message is a replacement for using a message box. It allows the user to get that information and store it and analyze what is happening, it simply means I don't need to click through 100's of message boxes in a for loop. There is likely an equivalent for your 2010 version which is 

Trace.WriteLine

I would suggest get that up an  running at some point make things easier. 

https://adndevblog.typepad.com/manufacturing/2014/08/debug-ilogic.html

 

VBA has the same Debug.Print  ("Hello") and shows up in the immediate window.

 

 

There really is no difference between the case and if statement method. Case will be faster overall and easier to write and follow in the long run.

 

I did see errors in the previous code when running the rule in the assembly that had read only parts. The ilogic snippet was erroring out when trying to check if the iproperty contained Joist, I guess it tries to gain access as if to write to the property. I used on error resume next as a test the loop worked and then said I would change the snippet to the full API method using property sets and this works fine. 

https://knowledge.autodesk.com/search-result/caas/simplecontent/content/list-all-iproperties-and-how...

 

ilogic snippet:

 

iProperties.Value(oRefDoc.DisplayName,"Project", "Estimated Cost")

API Property Set:

 

Dim oPropertySet As PropertySet
		oPropertySet = oRefDoc.PropertySets.Item("Inventor Document Summary Information")
		oCategory = oPropertySet.Item("Category")

I eliminated any errors of parameters etc by commenting out that code and just see if the for loop and if statement can run without errors. 

 

Sub Main 
	  
	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
	Dim oPrice As Double

    ' 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 oPropertySet As PropertySet
		oPropertySet = oRefDoc.PropertySets.Item("Inventor Document Summary Information")
		oCategory = oPropertySet.Item("Category")
		
''		'Find the part by looking at category in each document using oRefDoc.DisplayName as the document reference
		If oCategory.Value = "Joist" Then
			MessageBox.Show("Message", "In Joist If Statement")

	'			Dim oG_L As Double
	'			oG_L = Parameter(oRefDoc.DisplayName, "G_L")
			
	'			'Price Calculation
	'			 oPrice = PJoist_UL * (oG_L / 12) ' with  G_L in inches, 
		
	'			'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 oCategory.Value = "Decking" Then
				MessageBox.Show("Message", "In Joist If Statement")
'				Dim oLength,oWidth As Double
'				oLength = Parameter(oRefDoc.DisplayName, "SheetMetalLength")
'				oWidth = Parameter(oRefDoc.DisplayName, "SheetMetalWidth")
'				oArea = oLength * oWidth
				
'				'Price Calculation
'				oPrice  = PDecking_UL * oArea ' with  G_L in inches, 
			
'				'Apply the pricing to each document
'				If oPrice <> 0
'					iProperties.Value(oRefDoc.DisplayName,"Project", "Estimated Cost") = oPrice
'				End If
		
		End If
		
    Next
End Sub

 

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

NachoShaw
Advisor
Advisor

I use Snagit Editor for my image markups & gifs. It also has this teared paper edge feature which i never use 😂

 

cutaway.png

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 44 of 72

cadman777
Advisor
Advisor

Here's a capture of the VBA window when it errors out on my attempted conversion:

cadman777_1-1631904127530.png

I don't know what word or line of code represents that object in Inventor VBA, so I can't look it up. How do I find out if I don't have intellisense?

Note: I'm not asking you to fix this for me.
Instead, I'm asking you to tell me how to go about finding the answer.

 

A few minutes later...

I copy-and-past the code into VB Studio, and I can see how easy it is to use intellisense. How the F*CK did Autodesk expect the average Inventor user to learn how to write 'macros' WITHOUT this??

 

This reminds me of when I tried to learn AutoLISP. I waited for Autodesk to provide a LISP editor. But after a wuile I quit waiting, b/c they were IGNORING their users. So I bought 'VisualLISP' and began using it to write LISP code. I NEVER would've been able to do that w/out that editor! Then, a number of G.D. YEARS later, Autodesk found it in their dark and dirty heart to BUY OUT VisualLISP and incorporate it into AutoCAD. TOO F*CKING LATE! I have more stories about TEXT Editors and other apps that Autodesk incorporated into AutoCAD, but ROYALLY BUTCHERED in the process. Anyway...I can't say much good about the kind of 'business' that Autodesk has foisted onto their customers of the past 20 years.

 

Thanx for the INTELLISENSE tip. I'll try it and then get back to you and see IF I can fix this to work on my system.

... 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 45 of 72

NachoShaw
Advisor
Advisor

ok

 

in VBA, iProperties & Paramters need to be declared first. iLogic has background functions doing this for you but in full coding, it needs to be done. in the API you can fin examples if you search for them in the search box. in the results panel on the right, scroll to the bottom and you can usually find a range of examples

 

Getting an iProperty value

Public Sub GetPropertySample()
    ' Get the active document.
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As Property
    Set invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox "Part Number: " & invPartNumberProperty.value
End Sub

 

Setting a Parameter value

Public Sub SetParameter()
    ' Get the Parameters object. Assumes a part or assembly document is active.
    Dim oParameters As Parameters
    Set oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
    
    ' Get the parameter named "Length".
    Dim oLengthParam As Parameter
    Set oLengthParam = oParameters.Item("Length")
    
    ' Change the equation of the parameter.
    oLengthParam.Expression = "3.5 in"
    
    ' Update the document.
    ThisApplication.ActiveDocument.Update
End Sub

 These can both be manipulated to set & get as needed.

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 46 of 72

A.Acheson
Mentor
Mentor

AAcheson_0-1631907008822.png

@cadman777  You are exactly where I think we all have been not being able to make headway in VBA. It is certainly different than the ilogic environment. You have the disadvantage of the old version of INV so there is some things that have been changed. Your working two environments now 😁 a PRO in the making. 

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

cadman777
Advisor
Advisor

This forum keeps bouncing me out. I like how "Keep me Signed in" works, like the IRS: Voluntary means Mandatory.

This is the 'new normal'...a bureaucrat driven society heading down the sewer.

 

Thanx for the lessons. I'll look a them and try to digest the whole thing (and not choke on it).

Apparently you have to 'declare' EVERYTHING in VBA/VB.Net, right?

 

Here's tab 2 of the error box that pops up:

 

cadman777_1-1631914868182.png

Looks like it's unable to properly process the recursive function.

... 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 48 of 72

cadman777
Advisor
Advisor

"a pro in the making"...preach it brutha!
This kind of 'hope' makes for a good night of scotch on the rocks...

 

Oh, and thanx for the visual reminder.

I keep forgetting to visit that 'Help'.

... 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 49 of 72

A.Acheson
Mentor
Mentor

Your in the ilogic environment again I guess. 

 

If you refer to message 43 you will see how I dealt with the part being read only. Is that part that it errors out on read only?

Code run using ilogic snippet will yield this error message which is the same as yours. 

AAcheson_0-1631916348739.png

 

Either change the ilogic snippet to the API (VB.NET) version or use the error catch and skipping for the For loop. The error catching is quick but not graceful, think 2 month old scotch vs a 20 year old Scotch 

 

 

On Error Resume Next 'Error catching
For
Each oRefDoc In oRefDocs

 Pay attention to the text here this differs in the older version of INV 

PropertySets.Item("Inventor Document Summary Information")

Working code

AAcheson_1-1631916474437.png

 

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

cadman777
Advisor
Advisor

No, the parts are FG parts, and not readonly.

I included the Error catching, and it ran all the way through, but still same result.

Only Decking worked.

I've gotta go for now.

Be back in 2 weeks.

Thanx both you guys for all your help.

This will sink-in over the next 2 weeks, after I massage it in 12 year scotch.

... 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 51 of 72

NachoShaw
Advisor
Advisor

In iLogic & VB.Net you can use a Try Catch to error trap as that allows you to do something on the error and continue. you cant do that in VBA. Think of it like this

 

Try and do something, if it works great but of it doesnt work, do something else. Its structured like this

Try
   'Do something here
Catch
   'Do something else if the Try fails
End Try

 

You do need to declare everything in VBA / VB.Net but its still better than iLogic. I create a Class in VB.Net as a document class that has all of the functions i need for that document. The when i create a new instance, i only need to pass the document path to create that document in code. After that, if i need anything like properties or parameters, i can easily call it without the overhead of declarations. For example

 

'My Class is called C_Part as a part document class

'create the instance
Dim CPD As New C_Part(DocPath)

Dim TestParam As String = CPD.GetParam(ParamName)
Dim TestProp As String = CPD.GetProp(PropName)

I can create infinite instances depending on how i need to interact with assembly documents so all of my declarations & functions are set up because they are part of my class.

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 52 of 72

A.Acheson
Mentor
Mentor

@cadman777  If your getting no responses in the filter section of your code and need to use the error trapping likely your conditions are not correct.These conditions will be different for each type of part in use G_L for lumber, G_L,G_W for ply board etc and have been filtered already by the category assigned.  An example of an error is a parameter not existing or different name etc, error trapping could help in these areas using the try catch method but ideally none should be needed. In the data set you provided all worked with no error trapping needed. As soon as your data set changes the potential will increase for errors.

 

Lots of messages boxes and get the value for each parameter to pop up before you try and set any iproperty. 
Try one part category at a time and test as you go. 

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

NachoShaw
Advisor
Advisor

The biggest thing iLogic is missing is a STOP function. I like to add in STOPs if i have some code not running properly then step through line by line to see where the issue is. Stepping though is F8 in VBA, F11 in Visual Studio, no where in iLogic...

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 54 of 72

cadman777
Advisor
Advisor

OK Guys, I'm back.

 

I did some more work on this with a rested brain after a week on holiday, and found that one category of my errors was bad spelling and wrong code for IV2010 (for example, accessing the Volume property). So I fixed all that.

 

By using 'MessageBox.Show' I narrowed down the other category of errors to the rule not seeing any of the ContentCenter parts.

 

So here's my question:

How can I access the CC parts using iLogic in IV2010?

 

I would try VBA but I always run into errors that I can't solve yet, so I'd rather try on iLogic since most of my rules are in iLogic/VBA.

 

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 55 of 72

A.Acheson
Mentor
Mentor

When you say CC parts are these custom and writable or are they read only? I think as the rule stands it tries to read all files and does not differentiate the file type.  Have you a screenshot of the errors and or can you post the code and indicate in the browser the parts being skipped. 

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

cadman777
Advisor
Advisor

Hi Alan,

 

I just saw this, but ran out of time today.

But will get to it on Sunday, hopefully.

 

By CC I mean ContentCenter parts that the FrameGenerator creates.

They are all read-write parts in my read-write library.

 

Meanwhile...

Earlier today I tried a number of things but nothing worked.

The first thing I did was look at the Object Model for some kind of clue about the structure of the FrameGenerator.
The 2nd thing I did was look at the VBA Object Library to find some connection or clue.

But nothing I found looked like it would work.

So I tried a few stupid things and they too didn't work.

The biggest clue was when I isolated the offending snippet and made it the only Case that would run, but it failed.

 

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 57 of 72

NachoShaw
Advisor
Advisor

Hey

 

The Frame Generator parts have a Property flag that identified them as a Content Center part but the parent Frame Generator assembly does not because that is not from the Content Center.

 

To check, you can call the Occurrence PropertySetExists-

oOcc.Definition.Document.PropertySets.PropertySetExists("ContentCenter")

CC.png

 

However the components in the FG assembly are sub components to that assembly so in your code you would need to loop that or access all components ignoring the assembly levels

modthemachine Accessing Assembly components 

 

This will look at all referenced components and check if its a ContentCenter component

 

  ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

    ' Get all of the leaf occurrences of the assembly.
    Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmDef.Occurrences.AllLeafOccurrences

    ' Iterate through the occurrences and print the name.
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oLeafOccs
        Dim sInfo As String = String.Empty
		
		sInfo = "Part name:" & oOcc.Name & vbNewLine
		sInfo = sInfo & "Is from Content Center: " & oOcc.Definition.Document.PropertySets.PropertySetExists("ContentCenter")

		sInfo = sInfo & vbNewLine
		'For parts placed from Content Center check if it was place As Standard or As Custom

		If oOcc.Definition.Document.PropertySets.PropertySetExists("ContentCenter") Then
			If oOcc.Definition.IsContentMember Then
				sInfo = sInfo & "And placed As Standard"
			Else
				sInfo = sInfo & "And placed As Custom"
			End If
		End If	
		MsgBox(sInfo)
    Next

 

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 58 of 72

cadman777
Advisor
Advisor

Thanx for this tip!

 

Believe it or not, I had read that same web page many times, but didn't remember it in all the mental drain of trying to figure out what was wrong with my code. The thought did occur to me that I needed to 'walk the tree', which is why I looked at the Object Model 'tree', but that's as far as my memory would take me. The thing is, IF this stuff was made readily available to us, it would be so much easier to learn it. Anyway...

 

I'm going to try to integrate it into the code you guys have provided and see if my progress in learning it is any better than before. Will update when results come in. This is a good test scenario for me since this is the area where I always have trouble - integrating chunks of code into other chunks of code.

 

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

cadman777
Advisor
Advisor

Incidentally, this is what I had in mind when checking the sources I looked at:

"The Frame Generator parts have a Property flag that identified them as a Content Center part but the parent Frame Generator assembly does not because that is not from the Content Center."

I was trying to find a way to identify what was a CC part and then try to add in another level of filtering to the code.

However, I couldn't find it.

How did you know about it?

What resource did you use?

Did you find it in the 'F2' Object Library?

... 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 60 of 72

cadman777
Advisor
Advisor

OK, I tried running your rule and it failed.

I believe I fixed the first error by changing this line:

Dim sInfo As String = String.Empty

to this:

 

Dim sInfo As String = ""

 

But this line I can't figure out how to fix:

If oOcc.Definition.Document.PropertySets.PropertySetExists("ContentCenter") Then

The offending word is "PropertySetExists".

This is what the Object Browser has for Members of 'PropertySets' (it's a 'Class'):

PropertySetsMembers.JPG

There is no 'PropertySetExists' in the Object Browser.

I figured you're saying that if the 'ContentCenter' property exists in the component, then do something.

How do know whether or not "ContentCenter" is a valid property for IV2010 components?

Where do I look to find that info?

Is it a 'Type'?

If so, where do I find the list of component Types?
It's not in the Object Model.

Where is this information found?

 

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