Hi Bro.
I have code to add all parameter from code to assembly file. It worked. But if i run one more time. they are not stop but also add _1, _2 version => I would like to add some more line to stop if the parameter available already.
2. After created that parameter above to the assembly file => I would also coppy to all sub-assembly as the same name.
Could your please kindly help and support and improve.
Many thanks.
If ThisDoc.Document.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oMyParameter = ThisAssembly.Document.ComponentDefinition.Parameters.UserParameters Else oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters End If ''THIS WORKS NOTE PARAMETERS WILL BE ADDED IN THE EXACT ORDER THEY ARE GENERATED IN THIS LIST oParameter = oMyParameter.AddByExpression("extent_dim_X", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("extent_dim_Y", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("extent_dim_T", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("part_area", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("bend_number", "1", UnitsTypeEnum.kUnitlessUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("Xcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("Ycubic", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("Zcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits) oParameter.ExposedAsProperty = True oParameter = oMyParameter.AddByExpression("thread_hole_number", "1", UnitsTypeEnum.kUnitlessUnits) oParameter.ExposedAsProperty = True 'Next oParameter 'param.CustomPropertyFormat.Precision = kThreeDecimalPlacesPrecision 'param.CustomPropertyFormat.ShowTrailingZeros = True 'param.CustomPropertyFormat.ShowUnitsString = True 'param.CustomPropertyFormat.Units = "in" iLogicVb.UpdateWhenDone = True
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by FINET_Laurent. Go to Solution.
Hi,
Here is my go at it, this code creates the said parameters in the assembly you are firing the rule from, then goes through each sub-assembly and also creates those same parameters. It also prevents parameters from duplicating :
Sub Main() Dim Doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument Dim AssyCompDef As Inventor.AssemblyComponentDefinition = Doc.ComponentDefinition Create_Params(Doc) For Each Occ As Inventor.ComponentOccurrence In AssyCompDef.Occurrences Dim RefDoc As Inventor.Document = Occ.ReferencedDocumentDescriptor.ReferencedDocument Create_Params(RefDoc) Next End Sub Private Sub Create_Params(doc As Inventor.Document) Dim CompDef As Inventor.ComponentDefinition = doc.ComponentDefinition Dim UserParams As Inventor.UserParameters = CompDef.Parameters.UserParameters Dim pNames As String() = {"extent_dim_X", "extent_dim_Y", "extent_dim_T", "part_area", "bend_number", "Xcubic", "Ycubic", "Zcubic", "thread_hole_number" } Dim pValues As String() = {"1", "1", "1", "1", "1", "1", "1", "1", "1" } Dim pUnits As Object() = {UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kUnitlessUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kMillimeterLengthUnits, UnitsTypeEnum.kUnitlessUnits } For i As Integer = 0 To pNames.Length - 1 Dim check As Boolean = False For Each p As Inventor.Parameter In UserParams If p.Name = pNames(i) Then check = True Next If check = True Then Continue For Dim newParam As Inventor.Parameter = UserParams.AddByExpression(pNames(i), pValues(i), pUnits(i)) newParam.ExposedAsProperty = True Next End Sub
Please mark this as solution if it helped out ! 😄
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Hi @tamnn.designer. Attached is a text file of another iLogic rule I had that you could try for this task. I customized the parameter data to match the data you posted above. And customized it to only work on referenced sub assemblies, at all levels.
Edit: Oops, it does not do the 'Exposed as Property' and related settings part. But that could easily be added into the Sub routine's code, in if needed.
Wesley Crihfield
(Not an Autodesk Employee)
This version is customized a bit further, to expose the parameter as a custom iProperty then set the options the way you have them in your first post.
Wesley Crihfield
(Not an Autodesk Employee)
Hi Sir,
i am doing the stupid way. I use 2 code.
Frist. Add all parameter from external rule into the main assembly and Sub-Assembly
Second: I copied all parameter from the current main assembly into all children part.
=> Parameter from Assemblies = Parts. That is not good for me later. I would choose which parameter will add into Assemblies, and which parameters will go all children parts.
Finally: One code combination 2 step but choose the destination
- I would want all parameter in this code input to all parts.
- Some parameter Xcubic, Ycubic and Zcubic input to main assembly and sub-assembly only "
Thank a lot and best regards
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub
Dim oADoc As AssemblyDocument = ThisDoc.FactoryDocument
Dim oParamsData As New List(Of List(Of Object))
oParamsData.Add(New List(Of Object) From {"extent_dim_X", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"extent_dim_Y", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"extent_dim_T", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"part_area", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"bend_number", "1", UnitsTypeEnum.kUnitlessUnits })
oParamsData.Add(New List(Of Object) From {"Xcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"Ycubic", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"Zcubic", "1", UnitsTypeEnum.kMillimeterLengthUnits })
oParamsData.Add(New List(Of Object) From {"thread_hole_number", "1", UnitsTypeEnum.kUnitlessUnits })
EnsureParamsExist(oADoc, oParamsData)
Dim oAllSubAsms As List(Of Inventor.Document) = oADoc.AllReferencedDocuments.OfType(Of Inventor.Document).Where(Function(d) d.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject).ToList
If oAllSubAsms Is Nothing OrElse oAllSubAsms.Count = 0 Then Exit Sub
For Each oSubAsm In oAllSubAsms
EnsureParamsExist(oSubAsm, oParamsData)
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)
End Sub
Sub EnsureParamsExist(oDoc As Document, oParamsData As List(Of List(Of Object)))
If oDoc Is Nothing Or (oParamsData Is Nothing OrElse oParamsData.Count = 0) Then Exit Sub
If oDoc.IsModifiable = False Then Exit Sub
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
For Each MainEntry In oParamsData
If MainEntry.Count = 0 Then Continue For
Dim oUParam As UserParameter = Nothing
Try
oUParam = oUParams.Item(MainEntry.First)
Catch
oUParam = oUParams.AddByExpression(MainEntry.First, MainEntry.Item(1), MainEntry.Last)
End Try
Try
If Not oUParam.ExposedAsProperty Then oUParam.ExposedAsProperty = True
Dim oCPF As CustomPropertyFormat = oUParam.CustomPropertyFormat
oCPF.Units = oDoc.UnitsOfMeasure.GetStringFromType(MainEntry.Last)
oCPF.Precision = CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
oCPF.ShowLeadingZeros = True
oCPF.ShowTrailingZeros = True
Catch
End Try
Next
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.