How To Customize and Automate Drawing Commands with iLogic

fy25-inventor-campaign-02.jpg

Tired of repeating the same input or command over and over? There are a lot of advantages to automating simple processes. Cutting down on simple errors and creating documents that are uniform is just a few of them. The code below offers an easier way to use the chamfer command. I believe all of use have gotten tired of counting chamfer quantities, especially when we have different sized ones inside our designs.

 

This code will allow us so use a chamfer command and add a qty note to the text string. Adding the string to call out qty is relatively simple and so is finding the chamfer inside a sheet metal part. I've added some handling for a multibody derived part as well. This makes it a little tricker but still manageable and our code very robust.

 

Also, there is an optional dialog box that will tell the user that a drawing file is not open, regardless the rule is set up to exit if anything other than a drawing file is open and active.

 

This rule is still in the developmental stage. Please provide any feed back or ideas to make it more robust. Please share your thoughts as well. If you have any questions or future ideas you'd like to see, please leave them in the comments. Don't forget to like below please.

 


'exit rule if not a drawing file
If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then 'optional dialog box 'Call MsgBox("File not a Drawing...", vbOKOnly, "Custom iLogic Chamfer Creator...") Exit Sub End If 'set reference to active document Dim oIDWDoc As DrawingDocument = ThisApplication.ActiveDocument 'get refence to active sheet Dim oSheet As Sheet = oIDWDoc.ActiveSheet 'select edge for second chamfer input Dim Edge1 As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select First Chamfer Edge") 'get selected edge curve parent reference Dim oEdge1Curve As DrawingCurve = Edge1.Parent 'get drawing view name Dim oDrawingView As DrawingView = Edge1.Parent.Parent 'get drawing view part number, no extension Dim oViewPartName As String oViewPartName = Replace(oDrawingView.ReferencedFile.DisplayName, ".ipt", "") 'select edge for second chamfer input Dim Edge2 As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select Second Chamfer Edge") 'get selected edge curve parent reference Dim oEdge2Curve As DrawingCurve = Edge2.Parent 'Create position for note oTG = ThisApplication.TransientGeometry oPos = oTG.CreatePoint2d(Edge1.Geometry.MidPoint.X + 2, Edge1.Geometry.MidPoint.Y + 2) Dim oChamferNote As ChamferNote = oSheet.DrawingNotes.ChamferNotes.Add(oPos, oEdge1Curve, oEdge2Curve) 'get chamfer length as String aArray = Split(oChamferNote.Text, " ") oChamferLengthString = "(" & aArray(0) & " in)" '---get qty of chamfer--- 'set refence to the document referenced in the drawing view Dim oRefDoc As Document = oDrawingView.ReferencedFile.DocumentDescriptor.ReferencedDocument 'find multibody model info or if not multi-body then return needed value Dim oParentDoc As PartDocument Dim oCornerChamfer As CornerChamferFeature If oRefDoc.ReferencedDocuments.Count = 0 Then oCornerChamferFeatures = oRefDoc.ComponentDefinition.Features.CornerChamferFeatures For Each oChamferFeature In oCornerChamferFeatures If oChamferFeature.ExtendedName = oChamferLengthString Then oCornerChamfer = oChamferFeature Exit For End If Next Else 'referenct to parent document, when multibody modeling oParentDoc = oRefDoc.ReferencedDocuments.Item(1) oParentDocSB = oParentDoc.ComponentDefinition.SurfaceBodies 'find surface body by checking view part number against list of surface bodies in a multi body model Dim oBody As SurfaceBody For Each oBody In oParentDocSB oBodyInternalName = oBody.ComponentDefinition.Document.InternalName If oBody.Name = oViewPartName Then 'retreive the number of instances for qty in a definition For Each oCornerChamfer In oBody.ComponentDefinition.Features.CornerChamferFeatures If oCornerChamfer.Faces.Item(1).Parent.Name = oViewPartName Then oCornerChamfer = oCornerChamfer Exit For End If Next Exit For End If Next End If 'set qty string in chamfer note do not add qty if count is 1 'If Not IsEmpty(oCornerChamfer) Then Try If oCornerChamfer.Faces.Count <> 1 Then oChamferNote.FormattedText = oCornerChamfer.Faces.Count & "X <ChamferNote/>" End If Catch End Try 'End If