Automatically place parts and assemblies on a drawing

Automatically place parts and assemblies on a drawing

GKPByDesign
Advocate Advocate
442 Views
3 Replies
Message 1 of 4

Automatically place parts and assemblies on a drawing

GKPByDesign
Advocate
Advocate

I am trying to work with iLogic, but I am struggling. I just need a simple code to run on an open assembly and to begin creating 4 views of every assembly, sub assembly and part of the open file into a drawing with a decent scale. I do not want dims and for just the model files to be placed, can this be done? 

0 Likes
443 Views
3 Replies
Replies (3)
Message 2 of 4

GKPByDesign
Advocate
Advocate

I found some code that looks good, created by Clint Brown, but I have two issues with it

 

- I use idw as my drawing template not dwg

- I need the code to run through all parts and sub assemblies. 

 

Any suggestions

 

'Check if this is a drawing file
Dim doc = ThisDoc.Document
If doc.DocumentType = kDrawingDocumentObject Then
GoTo DRAWINGcode :
End If

'In parts & asemblies - Write file name and path to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\part.txt")
oWrite.WriteLine(ThisDoc.PathAndFileName(True))
oWrite.Close()
oFilePather = ThisDoc.Path & "\"

'In parts & asemblies - Write new drawing name to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\partno.txt")
oWrite.WriteLine(oFilePather & iProperties.Value("Project", "Part Number") & ".dwg")
oWrite.Close()

'Read Drawing name from text file
oRead = System.IO.File.OpenText("C:\TEMP\partno.txt")
EntireFile1 = oRead.ReadLine()
oRead.Close()
oDrawingName = EntireFile1

'Copy the Template file > keep templates saved in your project workspace, you need a separate part and assembly template
If doc.DocumentType = kAssemblyDocumentObject Then
oCopyFiler = "C:\Users\Clint\Workspace\ASSEMBLY_TEMPLATE.dwg"
Else If doc.DocumentType = kPartDocumentObject Then
oCopyFiler = "C:\Users\Clint\Workspace\PART_TEMPLATE.dwg"
End If

' Check if drawing exists - If it does, opening existing drawing
If System.IO.File.Exists(oDrawingName & DWGType) Then
MessageBox.Show("Drawing already exists > Opening Existing Drawing", "@ClintBrown3D")
ThisDoc.Launch(oDrawingName & DWGType)
Return
End If

'Launch New drawing
Dim oNewFiler As String = EntireFile1
System.IO.File.Copy(oCopyFiler,oNewFiler,(True))
ThisDoc.Launch(oNewFiler)

DRAWINGcode :
On Error GoTo Exiter
'Check if we have replaced the reference and scaled the drawing already
oNumbero = Parameter("Opened")
Parameter("Opened") = oNumbero + 1
'MsgBox(Parameter("Opened"))
If Parameter("Opened") > 2 Then
Return
End If

'Read in File name - For reference
oRead = System.IO.File.OpenText("C:\TEMP\part.txt")
EntireFile = oRead.ReadLine()
oRead.Close()
oPartPath = EntireFile

'Replace Drawing Reference
doc = ThisDoc.Document
Dim oFileDesc As FileDescriptor
oFileDesc = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFileDesc.ReplaceReference(oPartPath)
doc.Update()

'Read in new name for Drawing
oRead = System.IO.File.OpenText("C:\TEMP\partno.txt")
EntireFile1 = oRead.ReadLine()
oRead.Close()
oDrawingName = EntireFile1

'Save this drawing
ThisDoc.Save

'Scale the Drawing - Note your drawing views names("VIEW1")&("VIEW4") must match the template
On Error GoTo Exiter
oMyParameter = ThisDrawing.Document.Parameters.UserParameters
oParameter = oMyParameter.AddByValue("Scaler", "1:5", UnitsTypeEnum.kTextUnits)
MultiValue.SetList("Scaler","1:1", "1:2", "1:4", "1:5", "1:10", "1:20", "1:25", "1:50", "1:100")

Scaler = InputListBox("Set Drawing Scale", MultiValue.List("Scaler"), Scaler, Title := "Scale = " & ActiveSheet.View("VIEW1").ScaleString, ListName := "List")
ActiveSheet.View("VIEW1").ScaleString = Scaler
ActiveSheet.View("VIEW4").ScaleString = Scaler
Parameter.Param("Scaler").Delete

Exiter :
'Msgbox("Scale not Changed")
0 Likes
Message 3 of 4

GKPByDesign
Advocate
Advocate

in the latest versions of inventor the is now a " Open Drawing ' Bottom for every .iam or .ipt file. This creates a drawing view based on the current view within the open assembly/part. 

 

Is there a way to take this ' open drawing ' button and create an automated process?  no dimensions 

 

- Open Assembly 

- Run ilogic

- Create view of assembly from front, using a set drawing template

- use appreciate scale

- in the drawing create 3 additional views, side, plan (top) and upper right isometric

- return to assembly

- repeat for all parts/ sub assemblies

 

0 Likes
Message 4 of 4

GKPByDesign
Advocate
Advocate

I am still struggling with this, any ideas? 

0 Likes