Hello exprts!
I am trying to add a part template to an opened assembly, and then I would like to save it with a new name at a location (where project file exists) and then constraint it in the assembly.
I have written a following piece of code, but it looks like logic does not like the line where I am defining the TemplatesLoc value, basically telling the path where the templates are placed. What am I doing wrong here??
walls_no is a user defined parameter within the assembly file
Sub main() oAssyDoc = ThisApplication.ActiveDocument walls_no = GoExcel.CellValue("Control.xlsx", "Sheet1", "B4") Dim strPartName As String 'Dim PartName As String Dim oPosMatrix As Matrix Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry oPosMatrix = oTG.CreateMatrix Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = oAssyDoc.ComponentDefinition Dim TemplatesLoc as String TemplatesLoc = "D:\Working Folder\Freelancing\FIVERR - Muhammad\Templates\" Dim oPart As PartDocument oPart = ThisApplication.Documents.Add(kPartDocumentObject, TemplatesLoc & "Wall.ipt", True) MessageBox.Show("Message", "Title") oPart.ComponentDefinition.Parameters.UserParameters.AddByValue("LENGTH", wall_1_L, "mm") oPart.Update 'Dim strFileName As String Dim stroPartName As String wall_no = 1 strSaveLocation = ThisApplication.FileOptions.ProjectsPath stroPartName = "Wall" & wall_no strFileName = strSaveLocation & "\" & stroPartName & ".ipt" oPart.SaveAs(strFileName, True) oPart.Close(True) 'oPartName = strFileName Dim oOcc As ComponentOccurrence Dim oPartPlane As WorkPlane Dim oAssPlane As WorkPlane Dim oPartPlaneProxy As WorkPlaneProxy oOcc = oAssyDoc.ComponentDefinition.Occurrences.Add(strFileName, oPosMatrix) oOcc.Grounded = False oAssPlane = oAssyDoc.ComponentDefinition.WorkPlanes.Item(3) oPartPlane = oOcc.Definition.WorkPlanes.Item(3) Call oOcc.CreateGeometryProxy(oPartPlane, oPartPlaneProxy) Call oAsmCompDef.Constraints.AddFlushConstraint(oAssPlane, oPartPlaneProxy,0) End Sub
The code looks well. You can just check the template file exists and you can create new part manually from this template. When I replace your templates folder with my own, everything works fine.
really??? I wonder why isnt this working for my templates location. The template path and the template file do exists, but it still gives error at thee line where its trying to look for the template file!
Are you saying that when you run the code, it is getting the template file from the folder location and importing it into the assembly file??
Uhh, if I omit template file name then how will It find the template file from the location. Can you please elaborate on this, I don't understand.
A new rule would also need to get the template file from that location, so don't you think it would be redundant? Since the current rule is doing the same thing in a single rule?
Can't find what you're looking for? Ask the community or share your knowledge.