Hi
I have this code in one part, and it works ok.
But If I try to control the text from an assembly,
"I did a "Text Parameter" in assembly "Engraving"and that parameter is = whit a "Text Parameter" in part "EngravingL" from part and "EngravingL" it shoud be the text in the sketch."
I get this error.
Dim oPartDoc As PartDocument Dim oTextbox As TextBox oPartDoc = ThisApplication.ActiveDocument Dim oCd As ComponentDefinition Dim oSketch As PlanarSketch For Each oCd In oPartDoc.ComponentDefinitions For Each oSketch In oCd.Sketches For Each oTextbox In oSketch.TextBoxes oTextbox.Text = EngravingL Next Next Next
Can anyone help me?
Are you sure that the code runs only in the part and not in the assembly?
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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 !
The code is set in part.
As it is now, it doesn't work in the assembly. Maybe with some adjustments ... I would like it more if it worked from assembly
Hi @Cosmin_V
This worked for me to set the textbox value of each assembly sketch.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oDoc As Document
Dim oTextbox As TextBox
oDoc = ThisApplication.ActiveDocument
Dim oCd As ComponentDefinition
Dim oSketch As PlanarSketch
For Each oCd In oDoc.ComponentDefinitions
For Each oSketch In oCd.Sketches
For Each oTextbox In oSketch.TextBoxes
oTextbox.Text = "Test"
Next
Next
Next
Do you want to work with all local iLogic rules, or do you prefer external iLogic rules for this solution?
What action do you want to trigger the sketch text to change? Do you just want to run a local rule within the main assembly to make it all happen? Or maybe you want it so that when you change the value of the text parameter in the assembly, it causes a local rule within the assembly to run that will push that value to the part, then run a rule in the part to change the text in the sketch? It will be easier to set-up the parameter change triggering if you are using local rules in both cases, but it can also be done using external rules if needed (just requires more work/set-up).
If using local rules, and you want the change to happen when you change the parameter value within the main assembly, here is some example local iLogic rule codes you can try:
Within the main assembly document, create a new rule and copy/paste this following code into it. You will need to change the path & file name to the target Part file, or get the Part file in another way, if needed. (You can delete the comments, once you get it working OK.)
'try to specify/find/get the target part document
'it should already be 'initiated' because it's within the assembly, so we don't need to specifically open it
Dim oPDoc As PartDocument
Try
'<<<< CHANGE THIS PATH & FILE NAME >>>>
'or get the part document another way, if needed
oPDoc = ThisApplication.Documents.ItemByName("C:\Temp\MyPart.ipt")
Catch
MsgBox("Couldn't find the Part document named 'MyPart.ipt'. Exiting.")
Exit Sub
End Try
Dim oPrtParam As Inventor.Parameter
Try
oPrtParam = oPDoc.ComponentDefinition.Parameters.Item("EngravingL")
Catch
MsgBox("Couldn't find the parameter named 'EngravingL' within the Part. Exiting.")
Exit Sub
End Try
'set the value of the part's parameter to the value of the assemblies parameter
'when using a 'blue' local parameter name, it will trigger this rule to run when its value changes
oPrtParam.Value = Engraving 'local' parameter (should turn blue) within the Assembly
Then within the Part document, change its local rule code to this:
Dim oPDoc As PartDocument = ThisDoc.Document 'points to the 'local' document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
For Each oSketch As PlanarSketch In oPDef.Sketches
For Each oTextBox As Inventor.TextBox In oSketch.TextBoxes
oTextBox.Text = EngravingL 'local parameter (should turn blue)
Next
Next
You may have to update the part and/or assembly after wards to see the changes, or simply include an extra line of code in them to RebuildAll or Update.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
Hi @Cosmin_V
After reading WCrihfield's reply it occurred to me that you might be wanting to set the text in the sketches of all parts from the assembly.
Here are a couple more examples.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
This sets the same text to all parts
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oText = InputBox("Enter Text:", "iLogic", "Test")
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Dim oCd As ComponentDefinition
Dim oSketch As PlanarSketch
For Each oCd In oDoc.ComponentDefinitions
For Each oSketch In oCd.Sketches
For Each oTextbox In oSketch.TextBoxes
oTextbox.Text = oText
Next
Next
Next
End If
Next
InventorVb.DocumentUpdate()
This sets each part to use a different entered text value
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Dim oCd As ComponentDefinition
Dim oSketch As PlanarSketch
For Each oCd In oDoc.ComponentDefinitions
For Each oSketch In oCd.Sketches
For Each oTextbox In oSketch.TextBoxes
oText = InputBox _
("Enter Text for " & oDoc.DisplayName, "iLogic", oTextbox.Text)
oTextbox.Text = oText
Next
Next
Next
End If
Next
InventorVb.DocumentUpdate()
And here is an example that looks for a parameter in all the occurences named EngravingL and sets that if it is used (this assumes that parameter is being called into the text box)
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oText = InputBox("Enter EngravingL text:", "iLogic", "Test")
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences
Try
Parameter(oOcc.Name, "EngravingL") = oText
Catch 'error when parameter not found
End Try
Next
InventorVb.DocumentUpdate()
Hi everyone
No one works! 😞
It is a 4-piece ensemble. 3 have the same engraved code, and one another code.
I have set the code (from the first post) in all parts.
And I create a "Text parameter" in each part. (EngarvingL) which should be engraved on each part.
And in assembly I create 2 "Text parameter" "Engarving_Finger_Text" and "Engarving_Plate_Text"
And a rule ...
Parameter(o00292307.Name, "EngravingL") = Engraving_Finger_Text
Parameter(o00292308.Name, "EngravingL") = Engraving_Finger_Text
Parameter(o00292309.Name, "EngravingL") = Engraving_Finger_Text Parameter(o00292310.Name, "EngravingL") = Engraving_Plate_Text
And I put in form the parameters
Engraving_Finger_Text
Engraving_Plate_Text
Hi @Cosmin_V
If I put this rule in the assembly, it will update the parameter called EngravingL in the part file... when that parameter is used in the part sketch it will update to show both assembly parameter values, when those value are updated from the assembly form.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oTrigger = Engarving_Finger_Text
oTrigger = Engraving_Plate_Text
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences
Try
'set the parameter value in the part
Parameter(oOcc.Name, "EngravingL") = _
Parameter("Engarving_Finger_Text") & " " & Parameter("Engraving_Plate_Text")
Catch 'error when parameter not found
End Try
Next
InventorVb.DocumentUpdate()
Thank you very much!
But whatever I do, I get this error! 😞
Error in rule: Rule0, in document: 00292309.ipt
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Glad to hear you got it working OK. Issues involving multiple documents and multiple iLogic rules can sometimes be challenging for others to diagnose remotely. Here is a link to one of my contribution posts that I think you'll find interesting/helpful, that sort of relates to the problem you were having with the document reference. It attempts to help explain most of the different document references, and when/where they are best used. Good luck in your future iLogic endeavors.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.