I found this post to be quite useful:
I am banging my head against a wall trying to print to the freshly formatted part's Description using iProperties.Value("Project", "Description"), before iterating to the next part in the assembly.
Ultimately, I'm hoping to get a template that will have a nice conditional that will allow me to modify for each new ANSI profile we adopt in an Frame Assembly in addition to the formatting code in the link above. For instance, in Square Tubing, G_L is always equal to d19, so I'd write:
If G_L = d19
iProperties.Value("Project", "Description) = "=Sq Tube <Stock Number> x <G_L> LG."
Else
iProperties.Value("Project", "Description) = "=<Stock Number> x <G_L> LG."
Every attempt I make will at best apply the formula to the Assembly iProperties Description only.
Thanks, this would be a huge time saver on fabrication drawings.
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Solved by A.Acheson. Go to Solution.
This looks like you want to just alter descriptions of each frame member without altering cc family iprops etc? You are correct in saying that the iproperty that gets modified will be the main assembly. The iLogic API iproperty works by targeting the document the rule is in by default. For this kind of work I would prefer to go to the Inventor API as per your link. It is a more diffult route but your guaranteed to get feedback as to what object is failing and when and where. Can you give us more idea of what you want to achieve?
Your talking about template but if you are targeting frame generated members you won't be able to embed anything into the documents and so will have to have any changes applied externally. Is there anything in the previous link you posted that semi works for you? If it does please post your work and indicate what you might like to change.
So if your going the inventor API here are two articles that will help you get your head around. They will help guide you in creating small sample. Open a part and see can you get the iproperty and parameter interaction your after. Once you get this working then try and move into targeting all parts.
How to get an iproperty also called a property in Inv API
and another on how to implement written in vba.
Here is the vba sample for setting the value of a parameter.
I had the majority of a rule created so here is what I believe your looking for. The try catch is needed because if d19 parameter doesn't exist the rule would error out. If you want any help figuring out any lines let me know.
Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(asmDoc, "FG iproperty creation")
'Traverse all referenced documents
For Each doc As Document In asmDoc.AllReferencedDocuments
If doc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _' Frame generator component
AndAlso doc.DocumentType = DocumentTypeEnum.kPartDocumentObject _ 'Part
AndAlso doc.IsModifiable _'Not read only CC/Library document
AndAlso Not doc.DocumentInterests.HasInterest("SkeletonDoc") _'Not reference skeleton
AndAlso asmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(doc).Count > 0 Then 'Exists in assembly (not derived base component)
'Cast to a part document so we can use intelisense to identify part document properties and methods.
doc = TryCast(doc, PartDocument)
'Get propset equivalent of accessing iproperties tab 3.
Dim designPropSet As PropertySet = doc.PropertySets.Item("Design Tracking Properties")
'Access each iproperty.
Dim desc As [Property] = designPropSet.Item("Description")
Dim stkNum As [Property] = designPropSet.Item("Stock Number")
Dim compDef As PartComponentDefinition = doc.ComponentDefinition
'Get userparameter collection.
Dim UserParams As UserParameters = compDef.Parameters.UserParameters
'Get individual parameter.
Dim G_L As UserParameter = UserParams.Item("G_L")
Dim d19 As UserParameter
Try
d19 = UserParams.Item("d19")
'Check parameter values.
If G_L.Value = d19.Value Then
desc.Value = "Sq Tube " & stkNum.Value & "x" & G_L & "LG."
End If
Catch Ex As Exception 'Did not find parameter
desc.Value = stkNum.Value & "x" & G_L.Value & " LG."
End Try
End If
Next
trans.End
We WILL Sing Songs of your valor A.Acheson! At lease I will. This is great, I tweaked it a bit so it could be run before or after after I format the parts with the script linked to the original post. Tweak shown here:
Now, I should be able to copy this snippet and tweak it around if there are other profiles that need a custom name that isn't contained in the Stock Number, correct? That's what I plan on doing, that's what I meant when I spoke of "a template".
Again, thanks a million
Actually, I've run into a different issue. d19 is a Reference Parameter, so it IS successfully adding the formula "=<Stock Number...." to the description, it isn't catching and comparing the d19 value as expected. Any help?
Nice glad it worked out for you. Here is another article that deals with working with assembly components which is likely the biggest hurdle in all of this. O will be honest when I first looked at that article a few years ago I wasnt able to grasp how it all worked. Once you can wrap your head around how to get each object be it an occurrence or document then really its just a case of building up the different scenarios your going to encounter and applying methods and properties to them.
Yes you will need to declare it not as a userparameter but as a reference parameter. So access the referenceparameters collection and then declare it as a referenceparameter
Syntax Parameters.ReferenceParameters() As ReferenceParameters
Syntax
ReferenceParameters.Item( Index As Variant ) As ReferenceParameter
Awesome! Thanks again! I added ReferenceParams and it's friends to your script and, lo and behold, it worked like a dream.
You've added years to my life.
Can't find what you're looking for? Ask the community or share your knowledge.