- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
First of all, you guys are amazing, thank you for spending time helping people like this, it really makes this a great community to be a part of so I'm grateful for your time.
I have been trying like crazy to find the answer and I just can't figure it out, so hopefully it's something trivial I'm just missing.
I'm bravely diving into the wonderful and maddening world of automating assemblies.
When you use Constraints.AddFlush it creates a model parameter that corresponds to your newly created constraint.
I absolutely hate having them named useless things like "d89", so I'm of a mind to rename them something useful within the code.
The problem comes in that I'm creating a good many of them with each new ManagedComponentOccurrance I'm adding in, because naturally it makes sense to position and constrain them programmatically.
I would like an easy way to be able to get my model parameter being created at the same time as the constraint, so that I can rename the parameter.
Forgive my long iLogic code, I've been learning a lot so its about as inelegant as you might expect for someone learning.
imports system.IO Imports System.Linq Imports System.xml.linq Imports System.data.linq Sub Main Dim oTG = ThisApplication.TransientGeometry Dim doc = ThisDoc.Document Dim Path = ThisDoc.Path Dim ActiveDoc As AssemblyDocument ActiveDoc = ThisApplication.ActiveDocument Dim PurgeParams As Boolean PurgeParams = False Dim myParams As UserParameters myParams = ActiveDoc.ComponentDefinition.Parameters.UserParameters Dim myParam As UserParameter Dim myModParams As ModelParameters myModParams = ActiveDoc.ComponentDefinition.Parameters.ModelParameters Dim myModParam As ModelParameter Dim AsmComDef As AssemblyComponentDefinition AsmComDef = ActiveDoc.ComponentDefinition Dim di As DirectoryInfo = New DirectoryInfo(Path) Dim Part As ICadDoc Dim iLogicAuto = iLogicVb.Automation Dim ScallopFile As FileDescriptor Dim Scallop baseName = BaseNameOfScallop Dim ext As String ext = ".ipt" 'MsgBox("Got Past setting di of " & di.ToString) Dim initialPart As ManagedComponentOccurrence ThisAssembly.BeginManage("initialScallop") initialPart = ThisAssembly.Components.Add(BaseNameOfScallop & ":1", ThisDoc.Path & "/" & "ScallopSupport.ipt", , True) ThisAssembly.EndManage 'MsgBox(initialPart.tostring) Dim DirFilelist = di.GetFiles("*" & baseName & "*") 'MsgBox("files with basename in directory : " & DirFilelist.GetLength(0).ToString) Dim OriginPoint As Point OriginPoint = oTG.CreatePoint(0, 0, 0) 'MsgBox("Got past setting OriginPoint at " & OriginPoint.X & "," & OriginPoint.Y & "," & OriginPoint.Z) Dim OriPointToMatrix = oTG.CreateMatrix Try parameter("SeparationAmount") = parameter("SeparationAmount") Catch myParam = myParams.AddByExpression("SeparationAmount", "ZExtent / (NumOfScallopSupports - 1)", UnitsTypeEnum.kInchLengthUnits) End Try Dim myParamName As String Dim ParamSearch = (BaseNameOfScallop & "*" & "ZOffset") If NumOfScallopSupports > 0 Then ThisAssembly.BeginManage("Group 1") If NumOfScallopSupports = LastNumofScallopSupports Then PurgeParams = False Else PurgeParams = True End If If PurgeParams Then For Each myParam In myParams If myParam.Name Like ParamSearch Then myParam.Delete End If Next PurgeParams = False End If 'ThisAssembly.Components.Add("ScallopSupport:1", "ScallopSupport.ipt", ThisAssembly.Document.ComponentDefinition.WorkPoints.Item(1), True, True) 'MsgBox("Got past setting ScallopSupport:1 in Components.add") Dim AsmGeo As IGeometry AsmGeo = ThisAssembly.Geometry 'MsgBox("Got past setting AsmGeo") Dim NumberReached = False Dim NextPartExists = False Dim PositionMatrix As Matrix PositionMatrix = oTG.CreateMatrix 'MsgBox("Got past setting PositionMatrix Of " & PositionMatrix.Translation.ToString) 'MsgBox("Got past setting SepAmmount Of " & SeparationAmount ) Dim TransformVector As Vector TransformVector = oTG.CreateVector(0, 0, 0) 'if we have to have more than one Scallop.. If NumOfScallopSupports >1 Then 'clean up all Ilogic added parameters in this assembly. 'MsgBox("done deleting old params") 'loop through every Scallop needed past the first one, which should already exist. For i = 2 To NumOfScallopSupports 'check if we have reached the end of our looping If Not NumberReached Then TransformVector.Z = SeparationAmount * i - SeparationAmount 'MsgBox("Gotpast setting TransformVector Of " & TransformVector.X & "," & TransformVector.Y & "," & TransformVector.Z & " ") PositionMatrix.Translation.AddVector(TransformVector) 'will this need to be pitched? if not everthing can be the same component. If Pitched = True Then '-------------------------------------- ' I'll tackle this part later, I just want the single file version working before I worry about the automatic file duplication part. '-------------------------------------- 'we need to make sure we have separate files for each, since values will not be the same. ' 'MsgBox("basename is : " & baseName) ' Dim MyChar() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9" } ' baseName = baseName.TrimEnd(MyChar) ' baseName = baseName.Trim ' 'MsgBox("basename trimmed is : " & baseName) ' 'MessageBox.Show(baseName) ' Dim newName As String ' newName = baseName & DirFilelist.GetLength(0).ToString & ext ' 'MessageBox.Show("NewName is set to: " & newName) ' Dim newFullPathAndName As String ' newFullPathAndName = ThisDoc.Path & "\" & newName ' MsgBox(newFullPathAndName) ' Dim info As New FileInfo(newFullPathAndName) ' Dim ID ' MsgBox(ThisAssembly.Components.Count & " components") ' iLogicVb.RunRule("ScallopSupport:1", "Duplicate") ' Dim ScallopUnique = Components.Add("ScallopSupport:" & i, "ScallopSupport" & i & ".ipt", position := PositionMatrix, grounded := False, visible := True, appearance := Nothing) ' MsgBox(ScallopUnique.Name) Else 'this else assumes pitched is false 'create all copies needed as geometry thats just an instance of the original scallopFile 'add in the first one. Scallop = Components.Add("ScallopSupport:" & i, "ScallopSupport.ipt", grounded := False, visible := True, appearance := Nothing) 'MsgBox(Scallop.Name) Dim ScallopOccPartDef As PartComponentDefinition ScallopOccPartDef = Scallop.Occurrence.Definition 'MsgBox(ScallopOccPartDef.MassProperties.Mass) Dim offsetParamName As String offsetParamName = Scallop.Name & "ZOffset" 'MsgBox(offsetParamName) Dim offsetCalc As String offsetCalc = "SeparationAmount * " & i & " - SeparationAmount" 'MsgBox(offsetCalc) 'check if my offset user parameter is created, if not, create it. Try parameter(offsetParamName) = parameter(offsetParamName) parameter(offsetParamName) = offsetCalc 'MsgBox(parameter(offsetParamName) & " <- Already there. ") Catch myParam = AsmComDef.Parameters.UserParameters.AddByExpression(offsetParamName, offsetCalc, UnitsTypeEnum.kInchLengthUnits) 'MsgBox(parameter(offsetParamName) & " <- had to create it") End Try Dim CompOcc As ComponentOccurrence CompOcc = AsmComDef.Occurrences.ItemByName(Scallop.Name) 'MsgBox(CompArg.Name & " is the CompOcc name") Dim CompOccName As String CompOccName = CompOcc.Name Dim YZPlane As WorkPlane Dim XZPlane As WorkPlane Dim XYPlane As WorkPlane Dim YZPlaneProx As WorkPlaneProxy Dim XZPlaneProx As WorkPlaneProxy Dim XYPlaneProx As WorkPlaneProxy '----------------------------- 'create my workplanes YZSubplane = ScallopOccPartDef.WorkPlanes(1) 'MsgBox(YZSubplane.Name) XZSubplane = ScallopOccPartDef.WorkPlanes(2) 'MsgBox(XZSubplane.Name) XYSubplane = ScallopOccPartDef.WorkPlanes(3) 'MsgBox(XYSubplane.Name) '---------------------------- 'create my geometry proxies ' AsmComDef.Occurrences.ItemByName(Scallop.Name).CreateGeometryProxy(YZPlane, YZPlaneProx) 'MsgBox(YZSubplaneProx.Name) AsmComDef.Occurrences.ItemByName(Scallop.Name).CreateGeometryProxy(XZPlane, XZPlaneProx) 'MsgBox(XZSubplaneProx.Name) AsmComDef.Occurrences.ItemByName(Scallop.Name).CreateGeometryProxy(XYPlane, XYPlaneProx) 'MsgBox(XYSubplaneProx.Name) 'add my constraints YZConstraint = Constraints.AddFlush("FlushYZ" & Scallop.Name, "", "YZ Plane", CompOccName, YZPlaneProx.Name, 0) For Each myModParam In myModParams MsgBox(myModParam.Name & " is the mymodparam.name") Try If myModParam.AttributeSets.NameIsUsed(Scallop.Name & "AttSet") = True Then Else myModParam.AttributeSets.Add(Scallop.Name & "AttSet") End If Catch End Try MsgBox(myModParam.Dependents) Next '--------------------- 'rename the constraint. ' 'How do I find the Index for this myModParams.Item([Index of the one I just created??]).name 'Can I use a Linq? How would I do that? ' myModParams.Item.Name = "mFlushYZ" & Scallop.Name ' myModParams.Item("mFlushYZ" & Scallop.Name).Expression = 0 XZConstraint = Constraints.AddFlush("FlushXZ" & i, "", "XZ Plane", CompArgName, XZPlaneProx.Name, 0) ' myModParams.Item().Name = "mFlushXZ" & Scallop.Name ' myModParams.Item("mFlushXZ" & Scallop.Name).Expression = 0 XYConstraint = Constraints.AddFlush("FlushXY" & i, "", "XY Plane", CompArgName, XYPlaneProx.Name, parameter(offsetParamName)) MsgBox(XYConstraint.Constraint.Name & "got past xyconstraint setting") 'myModParams.Item().Name = "mFlushXY" & Scallop.Name 'MsgBox(myModParams.Item(myModParams.Count).Name) 'myModParams.Item(myModParam.).Expression = offsetParamName End If MsgBox("looping again") End If If i = NumOfScallopSupports Then NumberReached = True LastNumofScallopSupports = NumOfScallopSupports MsgBox("changed Lastnumofscallopsupports") End If Next MsgBox("got out of loop") End If End If ThisAssembly.EndManage("Group 1") End Sub
Any help would be so amazing. Thanks!
Solved! Go to Solution.