Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to add part template to an assembly and saving it in diff location using ilogic

4 REPLIES 4
Reply
Message 1 of 5
sohaib.as01
233 Views, 4 Replies

Trying to add part template to an assembly and saving it in diff location using ilogic

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


	

 

Labels (1)
4 REPLIES 4
Message 2 of 5

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. 

Message 3 of 5

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??

Message 4 of 5

  • Template file name is optional parameter. Try to omit them.
  • Try to create new rule which just create new part document from template.
  • Try to debug your code line-by-line using Visual Studio. It can help you to identify the issue. 

 

Message 5 of 5

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.

Post to forums  

Autodesk Design & Make Report