Drawing automation ilogic modification request.

Drawing automation ilogic modification request.

tkddud711
Advocate Advocate
1,024 Views
8 Replies
Message 1 of 9

Drawing automation ilogic modification request.

tkddud711
Advocate
Advocate

Hello everyone.
Drawing automation rules that work in the assembly environment.
In the BOM structure, I would like to skip the structure rules below and perform them.

1. The inseparable structure type.
2. The phantom structure type.
3. The purchased structure type.
4. The reference structure type.
5. Subparts created in Frame Generator.
6. Assemblies and subparts created from bolted connections.

 

I would like to skip the above 6 and run the rule.
Is it possible?

image.png

--------------------------------

Sub Main
Dim doc As AssemblyDocument = ThisDoc.Document
Dim def As AssemblyComponentDefinition = doc.ComponentDefinition

' Specify the desired drawing template address
Dim templateFileName As String = "C:\Standard.dwg"

Dim dDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, templateFileName)
Dim sheet As Sheet = dDoc.ActiveSheet

FillSheet(sheet, doc)

For Each refDoc As Document In doc.AllReferencedDocuments
Dim newSHeet = dDoc.Sheets.Add()
newSHeet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize
FillSheet(newSHeet, refDoc)

Next
End Sub

Private Sub FillSheet(sheet As Sheet, doc As Document)
sheet.Name = doc.DisplayName

' Set drawing layout unit
Dim sheetW4 = sheet.Width / 5
Dim sheetH4 = sheet.Height / 5

Try
sheet.AddBorder("basic")
sheet.AddTitleBlock("ISO")
Catch
End Try

Try
' Specify front view position
Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4, sheetH4*2)
Dim baseView As DrawingView = sheet.DrawingViews.AddBaseView(doc, position, 1, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
Dim scale = CalculateScale(baseView)
baseView.Scale = scale

' Specify side view position
position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4 * 3, sheetH4*2)
Dim view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, scale)
scale = Math.Min(scale, CalculateScale(view))

' Specify top view position
position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4, sheetH4 * 4)
view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, scale)
scale = Math.Min(scale, CalculateScale(view))

' Specify isometric view position
position = ThisApplication.TransientGeometry.CreatePoint2d(sheetW4 * 3.5, sheetH4 * 3.5)
view = sheet.DrawingViews.AddProjectedView(baseView, position, DrawingViewStyleEnum.kShadedDrawingViewStyle, scale)
scale = Math.Min(scale, CalculateScale(view))

baseView.Scale = scale
view.Scale = scale
Catch ex As Exception
MsgBox("Something went wrong while creating sheet for model: " & doc.DisplayName)
Return
End Try
End Sub

' Specify drawing layout size ratio
Private Function CalculateScale(view As DrawingView) As Double
Dim scaleX = view.Parent.Width / view.Width / 3
Dim scaleY = view.Parent.Height / view.Height / 3
Return Math.Min(scaleX, scaleY)

End Function

 

--------------------------------

0 Likes
Accepted solutions (1)
1,025 Views
8 Replies
Replies (8)
Message 2 of 9

A.Acheson
Mentor
Mentor

Hi @tkddud711 

Yes this is possible. Here are some tips to get you started  Bom structure is accessed from the ComponentDefinition help page here

Syntax

ComponentDefinition.BOMStructure() As BOMStructureEnum

 

For frame generator method filter by has interest method here.

 

The bolt generator will have a unique id and this post here has a method to retrieve it. 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 9

tkddud711
Advocate
Advocate

thank you for the reply.
I am a beginner in writing code.
Could you please make the code?

0 Likes
Message 4 of 9

A.Acheson
Mentor
Mentor

As also once a beginner back in 2019 trying is the best form of learning. And when you get into this level of automation you really need to post the attempt your doing and ask specific question to request help. 

 

This is the loop you need to target

 

For Each refDoc As Document In doc.AllReferencedDocuments
Dim newSHeet = dDoc.Sheets.Add()
newSHeet.Size = DrawingSheetSizeEnum.kA3DrawingSheetSize
FillSheet(newSHeet, refDoc)

Next
End Sub

 I am assuming you know how to get to a definition from the document. 

 

For the frame generator the filter was kindly laid out in the linked post. All references to object oDoc needs to be your refDoc object. 

Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") = True
MsgBox("Created by Frame Generator")
Else
MsgBox("Not created by Frame Generator")
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 9

tkddud711
Advocate
Advocate

thank you
I solved it thanks to the information you provided.
Additionally, I have a question.

sheet.AddBorder("basic")
sheet.AddTitleBlock("ISO")

The above code creates a border and title block when adding a sheet.
But I want to use the sheet format,
In the BOM structure, the assembly uses the sheet format (A_A3),
I would like to use (B_A4) for anything other than assemblies.

Can anyone tell me the code above?

0 Likes
Message 6 of 9

A.Acheson
Mentor
Mentor

See API help page here for sheet formats

 

Sheets.AddUsingSheetFormatSheetFormat As SheetFormat, [Model] As Variant, [SheetName] As String, [AdditionalOptions] As Variant, [TitleBlockPromptStrings] As Variant, [BorderPromptStrings] As Variant ) As Sheet

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 9

tkddud711
Advocate
Advocate

With the information you provided, I applied the code to add a drawing in sheet format as shown below.
-------------------------------------------------- -----

    Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
    Dim oFormat As SheetFormat
Try
        oFormat = oDoc.SheetFormats.Item("A3")
    Catch
    MessageBox.Show("Error: Drawing format does not exist.", "iLogic")
    End Try
    Dim newSheet As sheet = oDoc.Sheets.AddUsingSheetFormat(oFormat)
    FillSheet(newSheet, refDoc)
    Next
    End Sub
 
Private Sub FillSheet(sheet As Sheet, doc As Document)
    sheet.Name = doc.DisplayName

-------------------------------------------------- -----

However, I don't know how to apply the sheet format to assemblies and parts separately.

I would like to inquire again.
The assembly is applied in sheet format (A_A3).
I would like to apply the part in sheet format (B_A4).

Is there anyone who can edit the code above?

0 Likes
Message 8 of 9

A.Acheson
Mentor
Mentor
Accepted solution

You will need to check the document object supplied to create the view. See help page for documentType

Syntax

Document.DocumentType() As DocumentTypeEnum

 

Edited to remove spelling error

 

If refDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'Do Something
ElseIf refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
'Do Something
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 9

tkddud711
Advocate
Advocate

I was stuck for a while because I got an error.
DoumentTypeEnum.kAssemblyDocumentObject
Modified to DocumentTypeEnum.kAssemblyDocumentObject.

thank you
Thanks to your help, I completed the code.