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: 

Get iproperty from nested component using iLogic?

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Curtis_Waguespack
337 Views, 11 Replies

Get iproperty from nested component using iLogic?

Does anyone know if there's an iLogic function to do this. I feel like I might be forgetting or missing something, and want to confirm that I am not, before going the path of using the API for this.

 

Here's the set up:

( see attached Inventor 2024 file also)

I have a part that is nested down deep in an assembly, that I want to work with from the drawing view of the top level, as shown.

Curtis_Waguespack_0-1723666045645.png

 

I can use Capture Current State to get an edge intent and place a dimension on that part, from the drawing view of the top level assembly, that works great.

Curtis_Waguespack_1-1723669139842.png

 

Dim Front_Edge = VIEW1.GetIntent({"1111:1", "111:1", "11:1", "Part 1:1"}, "Front Edge")

 

I can use Capture Current State to get a parameter value in that part, from the drawing view of the top level assembly, that works great also.

Curtis_Waguespack_0-1723669071362.png

 

oDia = Parameter("Part 1.ipt.Diameter")

 

I can use MakePath to set the arraylist of the path down to the part, that seems to work

pathArray = MakePath({"1111:1", "111:1", "11:1", "Part 1:1" })

 

But I can not use the MakePath arraylist, or use the {curly bracket array string} to access the iProperty of the part.

These don't work:

PMK = iProperties.Value(pathArray, "PIECEMARK") 
PMK = iProperties.Value({"1111:1", "111:1", "11:1", "Part 1:1" }, "PIECEMARK") 

full example:

Dim Sheet_1 = ThisDrawing.ActiveSheet
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions
Dim Pt = VIEW1.SheetPoint(-0.25, -0.45)

Dim Front_Edge = VIEW1.GetIntent({"1111:1", "111:1", "11:1", "Part 1:1"}, "Front Edge")
Dim holeDim = genDims.AddDiameter("Dia1", Pt, Front_Edge)

oDia = Parameter("Part 1.ipt.Diameter")
MsgBox(oDia)

pathArray = MakePath({"1111:1", "111:1", "11:1", "Part 1:1" })

'PMK = iProperties.Value(pathArray, "PIECEMARK") 
'PMK = iProperties.Value({"1111:1", "111:1", "11:1", "Part 1:1" }, "PIECEMARK") 
'MsgBox(PMK)

 

11 REPLIES 11
Message 2 of 12
cidhelp
in reply to: Curtis_Waguespack

Hello @Curtis_Waguespack ,

 

have you tried:

PMK = iProperties.Value("Part 1:1", "Custom", "PIECEMARK")

It's not logically without the path, but it's working on my side (from the assembly). I have not tested from the drawing.

Message 3 of 12
Curtis_Waguespack
in reply to: cidhelp

Hi @cidhelp ,

 

Thanks for the reply. It does work in the top level assembly, but unfortunately not in the drawing of that same assembly.

 

The error returned attempting to use that line does provide the following information about the arguments expected by the iLogic iProperties .value function though

System.ArgumentException: iProperties: The component named "Part 1:1" was not found.
   at iLogic.CadPropertiesInRule.FindCompoOrDoc(Object compoOrDocName, Boolean needFactory)
   at iLogic.CadPropertiesInRule.InvPropertyInCompoOrDoc(Object compoOrDocName, String setName, String propName, Boolean createCustom, Document& doc, Boolean needFactory)
   at iLogic.CadPropertiesInRule.get_Value(Object compoOrDocName, String setName, String propName)
   at ThisRule.Main() in rule: Rule0, in document 11111.idw:line 15
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Message 4 of 12
cidhelp
in reply to: Curtis_Waguespack

Hallo @Curtis_Waguespack ,

 

the compOrDocName in the error-message looks like you can also use the documents name.

I tried:

iProperties.Value("Part 1.ipt", "Custom", "PIECEMARK")

and it worked from the drawing.

Message 5 of 12

As long as that lowest level document is within the 'AllReferencedDocuments' collection of the drawing, you will be able to reach it with the 'iProperties.Value()' snippet in a rule in that drawing.  If just specifying the referenced document 'name' directly (as suggested in previous post) does not work reliably in more complex scenarios, then you can likely use a few more lines of 'iLogic' code (with a tiny bit if Inventor API in there) to get there a different way.

oOcc = Components.Item({"1111:1", "111:1", "11:1", "Part 1:1" }).Occurrence
SOP = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
PMK = SOP.iProperties.Value("Custom", "PIECEMARK")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 12
Curtis_Waguespack
in reply to: cidhelp

@cidhelp, yeah that's what I noticed too. 

 

I was really hoping not to need to loop through the occurrences to find the document name, but I'm just not seeing a better way. That's why I was thinking/hoping I was overlooking something.

 

Dim oSheet = ThisDrawing.ActiveSheet
Dim oView = oSheet.DrawingViews.ItemByName("VIEW1")
Dim oViewModelDoc As AssemblyDocument = ActiveSheet.View(oView.Name).ModelDocument

Dim oCompName As String = "Part 1:1"
For Each oOcc As ComponentOccurrence In oViewModelDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
	If oOcc.Name = oCompName Then
		Dim oDoc As Document = oOcc.Definition.Document
		Dim DocName As String = IO.Path.GetFileName(oDoc.FullFileName)
		oPMK = iProperties.Value(DocName, "Custom", "PIECEMARK")
	End If
Next
MsgBox(oPMK,,"iLogic")

 

 

Message 7 of 12

@WCrihfield 

 

I got excited when I saw your example, but it looks like the iLogic Components function is only for use in assemblies and pulls the ThisDoc document, so from a drawing it's getting the drawing doc and errors out.

 

Did I miss something for getting this to work from a drawing?

 

oOcc = Components.Item({"1111:1", "111:1", "11:1", "Part 1:1" }).Occurrence
SOP = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
PMK = SOP.iProperties.Value("Custom", "PIECEMARK")

 

Note: I tried this line previously too and it's only available in an assembly as well.

Dim compOcc = Component.InventorComponent("Part 1:1")

 

Just as a SWAG, I tried something like this, to get the IManaged assembly from the view model document, but no dice.

Dim oSheet = ThisDrawing.ActiveSheet
Dim oView = oSheet.DrawingViews.ItemByName("VIEW1")
Dim oDoc As AssemblyDocument = ActiveSheet.View(oView.Name).ModelDocument
Dim iMDoc As IManagedAssembly = oDoc

oOcc = iMDoc.Components.Item({"1111:1", "111:1", "11:1", "Part 1:1" }).Occurrence
SOP = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
PMK = SOP.iProperties.Value("Custom", "PIECEMARK")

MsgBox(oPMK,,"iLogic")

 

Do you know of a way to get an iManaged assembly from a drawing / drawing view?

Message 8 of 12

Nope.  The StandardObjectProvider thing just came to mind when looking at the situation, and I tried to think of the easiest way to get a reference to the document object needed for the input, using only (mostly) code that is unique to iLogic API, instead of Inventor API, but obviously did not test it before posting.  Another angle that came to mind was working backwards from that GeometryIntent to get a reference to that lowest level document, but that would get a lot more more complicated, and involve plenty of Inventor API stuff, which I know you are trying to avoid here, so I didn't bother going there.  It would have led to a top level proxy anyways, then would have to dig down to original, then up to document.  Lots of steps, but likely possible.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 12

But just out of curiosity, would this work...

 

Dim oSheet = ThisDrawing.ActiveSheet
Dim oView = oSheet.DrawingViews.ItemByName("VIEW1")
Dim oDoc As AssemblyDocument = ActiveSheet.View(oView.Name).ModelDocument
SOP1 = iLogicVb.CreateObjectProvider(oDoc)
oOcc = SOP1.Component.InventorComponent({"1111:1", "111:1", "11:1", "Part 1:1" })
SOP2 = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
PMK = SOP2.iProperties.Value("Custom", "PIECEMARK")
MsgBox(PMK,,"iLogic")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

I had to do some local testing on my end to finally figure this out.  Too much stuff going on in my mind to keep the whole process straight. 😅  I finally got it to work though.  I think I finally just had to break down and actually 'declare' all my variables, before it would work for me properly.  I have encountered this several times before.  If certain things, or too many things, are not properly declared, with Type specified, it tends to get confused, or looses its code path, or something like that.  I left a couple lines in there, but commented out, just to show other lines I tested with.  Of course my 'test subjects' were named differently, because they are based on an already existing test assembly's drawing.

Dim oDDoc As Document = ThisDrawing.Document
Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oView As IManagedDrawingView = ActiveSheet.View("VIEW1")
Dim oModel As Document = oView.ModelDocument
Dim SOP1 As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oModel)
'this one did not work for me...needs component path specified
'Dim oOcc As ManagedComponentOccurrence = SOP1.ThisAssembly.Components.Item("Coordinates Part:1")
'this next one worked OK
Dim oOcc As ManagedComponentOccurrence = SOP1.ThisAssembly.Components.Item({"Component Matrix Tests:1", "Coordinates Part:1" })
'this next one also worked OK for me
'Dim oOcc As ComponentOccurrence = SOP1.Component.InventorComponent({"Component Matrix Tests:1", "Coordinates Part:1" })
'this next one works, when the last line was used
'Dim SOP2 As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
'this next line works OK when you got a ManagedComponentOccurrence
Dim SOP2 As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oOcc.Occurrence.Definition.Document)
Dim sVal As String = SOP2.iProperties.Value("Project", "Part Number")
MsgBox(sVal.ToString, , "iLogic")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 12

@WCrihfield this is great! Thanks for digging into this.

 

I've never used the ObjectProvider, so I think this is the gem I was looking for. 

I appreciate the thoroughness of the results you posted. I think I will stash this version in my bag of tricks. 

 

Note too that it will handle a Makepath arraylist which is very nice.

Dim oDDoc As Document = ThisDrawing.Document
Dim oSheet As Sheet = ActiveSheet.Sheet
Dim oView As IManagedDrawingView = ActiveSheet.View("VIEW1")
Dim oModel As Document = oView.ModelDocument
Dim SOP1 As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oModel)

Dim mkPath As ArrayList = MakePath({"1111:1", "111:1", "11:1", "Part 1:1" })
Dim oOcc As ComponentOccurrence = SOP1.Component.InventorComponent(mkPath )

Dim SOP2 As IStandardObjectProvider = iLogicVb.CreateObjectProvider(oOcc.Definition.Document)
Dim sVal As String = SOP2.iProperties.Value("Custom", "PIECEMARK")

MsgBox(sVal.ToString, , "iLogic")

 

Message 12 of 12

I think I picked that up from Mike Deck on a forum post back in 2019 when I was commenting about how to access the iProperties of lower level referenced documents in an assembly using that iProperties.Value() snippet.  I had mentioned the lack of documentation about how to specify a document to reference in the online help area for these types of snippets, and lack of explanation about which document it will naturally access when no document specification is provided, in different scenarios.  I think it became available in the 2020 version of Inventor, but I could be remembering wrong.  Makes specifying which document (precisely) you want to access the iProperties (or something else) of, without needing the usual long line of Inventor API code.

 

Wish I still had that link available to post here, but I either did not keep it, or lost it.  I lost a bunch of my custom iLogic snippets earlier in the year, and it may have been in one of those.  I had multiple exported files for my custom snippets, and was clearing some of them out.  I figured the one with the latest date was the 'active' one, but apparently I was wrong.  Next day half a year worth of custom snippets was gone, and could not be recovered by back-up, due to timing issue.  Now I export a new copy every few days, to be safe.

 

Edit:  Found the link...I was way off.  The post was in early 2022, and code tool became available in 2021 version.

https://forums.autodesk.com/t5/inventor-programming-ilogic/retreaving-custom-iproperty/m-p/10955051/... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Autodesk Design & Make Report