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: 

iLogic Coding to Create Automated Drawing

132 REPLIES 132
SOLVED
Reply
Message 1 of 133
mehatfie
43362 Views, 132 Replies

iLogic Coding to Create Automated Drawing

Hi all,

I'm attempting to create a model that autmotaically derives ready-to-go drawings. I've gotten pretty far in doing so but have a few issues with regards to dimensioning. As I'm sure you're aware, when the model changes, a dimension to that feature, which has been removed, is also deleted and some those dimensions do not return once the model is changed back.

I have looked into using different view representations, but have found that they do not accommodate feature supression.

My questions are:

Is there a way to program in the dimensioning of a view

Create center points for of of the holes and center lines

And for a feature note such as "Hole and Thread" dimensioning, when the model expands, the leader and text length do not change and proceed into the view. Is there a way to fix or anchor the text to a certain spot on the drawing, and have the leader length expand and change accordingly to that point.

If you would like farther information, or think a similar question would help, please ask. Thanks in advance for any help.

Mitch

132 REPLIES 132
Message 101 of 133
mehatfie
in reply to: Eddie.trooper

Hi Shiva,

 

I'm not quite sure I understand your question. Are you asking if there is any way to use this code in the drawing file instead of running it from the assembly?

 

The code I created was designed to run from the assembly file at the start, the dimensioning functions should be fine to run within the drawing itself.

 

Can you please give a more descrptive scenario of what you're trying to do? I believe I can help you, I just need a better understanding.

 

For the dimensioning between circles, the first thing I would go through is to check your model, parameters, and dimension you're entering into the code. Inventor is very sensitive and if the dimension is some how 0.000001 off, iLogic will not be able to locate it in the drawing.

 

 

Regards

Mitch

Message 102 of 133
karram
in reply to: mehatfie

Hello,

 

             This is VBA Code for automatic creation of Drawings in Assembly file. Here i got one small difficulty, while  creations of section views

 

In that attachment code,

              ' Get the circular edge of the top of the part.
    Dim oObjs As ObjectCollection
    Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge11")
    Dim oCircularEdge As Edge
    Set oCircularEdge = oObjs.Item(1)

 

Highlighted line got error in this code.

 

Pls find the suitable solutions for this

 

Option Explicit



' This creates a toolbar with buttons for the macros to be demonstrated.
Public Sub CreateDemoToolbar()
    Dim oCommandBar As CommandBar
    Set oCommandBar = ThisApplication.UserInterfaceManager.CommandBars.Add("Drawing Automation Samples", "")
    oCommandBar.Visible = True
    
     
    ' Buttons for drawing view related samples.
    Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("modOverallDimensions.TestOverallDimensions")
    Call oCommandBar.Controls.AddMacro(oMacroDef)

    Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions.AddMacroControlDefinition("modSamples.MakeDrawing")
    Call oCommandBar.Controls.AddMacro(oMacroDef)

End Sub

' Demonstrates the ability to automatically create a drawing.  It's hard coded to look for edges
' with specific attributes attached.  The supplied model is already set up.
Public Sub MakeDrawing()

     
    ' Create a new drawing document using the default template.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "dwg", True)
    
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
      
    ' Open the part to be inserted into the drawing.
    Dim oAssemblyDoc As AssemblyDocument
    Set oAssemblyDoc = ThisApplication.Documents.Open("Assembly.iam", False)
    
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    MsgBox "Create base and orthographic views."
    
    ' Place the base front view.
    Dim oFrontView As DrawingView
    Set oFrontView = oSheet.DrawingViews.AddBaseView(oAssemblyDoc, oTG.CreatePoint2d(12, 15), 5, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
    
    ' Create the top, right and iso views.
    Dim oTopView As DrawingView
    Set oTopView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(12, 30), kFromBaseDrawingViewStyle)
    
    Dim oIsoView As DrawingView
    Set oIsoView = oSheet.DrawingViews.AddProjectedView(oFrontView, oTG.CreatePoint2d(44, 33), kHiddenLineRemovedDrawingViewStyle)

    MsgBox "Create section view."
    
    ' Create a front section view by defining a section line in the front view.
    Dim oSectionSketch As DrawingSketch
    Set oSectionSketch = oFrontView.Sketches.Add
    
    oSectionSketch.Edit
    
    ' Get the circular edge of the top of the part.
    Dim oObjs As ObjectCollection
    Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge11")
    Dim oCircularEdge As Edge
    Set oCircularEdge = oObjs.Item(1)

    ' Get the associated drawingcurve.
    Dim oDrawViewCurves As DrawingCurvesEnumerator
    Set oDrawViewCurves = oFrontView.DrawingCurves(oCircularEdge)
    Dim oCircularCurve As DrawingCurve
    Set oCircularCurve = oDrawViewCurves.Item(1)
    
    Dim oCircularEntity As SketchEntity
    Set oCircularEntity = oSectionSketch.AddByProjectingEntity(oCircularCurve)
    
    ' Draw the section line.
    Dim oSectionLine As SketchLine
    Set oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0.9), oTG.CreatePoint2d(0, -0.9))
    
    ' Create a constraint to the projected circle center point and the line.
    Call oSectionSketch.GeometricConstraints.AddCoincident(oSectionLine, oCircularEntity.CenterSketchPoint)
    
    oSectionSketch.ExitEdit
    
    ' Create the section view.
    Dim oSectionView As SectionDrawingView
    Set oSectionView = oSheet.DrawingViews.AddSectionView(oFrontView, oSectionSketch, oTG.CreatePoint2d(24, 10), kHiddenLineRemovedDrawingViewStyle, , False)
        
    MsgBox "Create detail view."
    
    ' Create the detail view.
    Dim oDetailView As DetailDrawingView
    Set oDetailView = oSheet.DrawingViews.AddDetailView(oSectionView, oTG.CreatePoint2d(35, 15), kFromBaseDrawingViewStyle, True, oTG.CreatePoint2d(23, 16), 2, , 5, , "A")

    ' Get the various edges of the model.
    Dim aoEdges(1 To 12) As Edge
    Dim i As Integer
    For i = 1 To 12
        Set oObjs = oAssemblyDoc.AttributeManager.FindObjects("Name", "Name", "Edge" & i)
        Set aoEdges(i) = oObjs.Item(1)
    Next
    
    ' Get the equivalent drawing curves.
    Dim aoDrawCurves(1 To 12) As DrawingCurve
    For i = 1 To 12
        Set oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))
        Set aoDrawCurves(i) = oDrawViewCurves.Item(1)
    Next
    
    MsgBox "Create dimensions to the curves in the view."
    
    ' Create some dimensions
    Dim oGeneralDims As GeneralDimensions
    Set oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
    Dim oDim As GeneralDimension
    Set oDim = oGeneralDims.AddLinear(oTG.CreatePoint2d(7, 15), oSheet.CreateGeometryIntent(aoDrawCurves(1)), oSheet.CreateGeometryIntent(aoDrawCurves(3)), kVerticalDimensionType)
    Set oDim = oGeneralDims.AddLinear(oTG.CreatePoint2d(12, 9), oSheet.CreateGeometryIntent(aoDrawCurves(2)), oSheet.CreateGeometryIntent(aoDrawCurves(4)), kHorizontalDimensionType)
    Set oDim = oGeneralDims.AddRadius(oTG.CreatePoint2d(16, 19), oSheet.CreateGeometryIntent(aoDrawCurves(8)))
    Set oDim = oGeneralDims.AddDiameter(oTG.CreatePoint2d(8, 20), oSheet.CreateGeometryIntent(aoDrawCurves(9)), True, False)
    
    MsgBox "Create a text box with a leader."
    
    ' Place a text box with a leader.
    Dim oObjColl As ObjectCollection
    Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection
    Call oObjColl.Add(oTG.CreatePoint2d(16.5, 15))
    Dim oEval As Curve2dEvaluator
    Set oEval = aoDrawCurves(4).Evaluator2D
    Dim adParams(0) As Double
    adParams(0) = 0.6
    Dim adPoints(1 To 2) As Double
    Call oEval.GetPointAtParam(adParams, adPoints)
    Call oObjColl.Add(oSheet.CreateGeometryIntent(aoDrawCurves(4), oTG.CreatePoint2d(adPoints(1), adPoints(2))))
    Dim oLeaderNote As LeaderNote
    Set oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oObjColl, "Text with a leader")
    oLeaderNote.DimensionStyle = oLeaderNote.DimensionStyle
End Sub


 

Thanks,

Karthick

Message 103 of 133
mehatfie
in reply to: Eddie.trooper

Hi Shiva,

 

Have you figured your issues out? It should be a Few tweaks in the code to allow it to run in the drawing 

 

Mitch

Message 104 of 133
mehatfie
in reply to: karram

HI Karthick,

 

Are you trying to create a section view from a circle drawing curve?

 

 

 

Mitch

Message 105 of 133
karram
in reply to: mehatfie

Hi Mitch,

      

                  Yes iam trying to create the section view from a circle drawing curve.

 

                  I Attached the sectional view image, which i did manually. So kindly try to fix this error.

 

Thanks

Karthick

Message 106 of 133
Eddie.trooper
in reply to: mehatfie

Hello Mitch,

 

Thanks for your reply, The code did work for the assembly drawings, but of it does not detect if the the dimension iam looking for is in the actual part and not in the assembly itself. Also the code does not detect the dimensioning between two holes as i said earlier.

 

Thanks,

Shiva

Message 107 of 133
Eddie.trooper
in reply to: karram

Hello karthick,

 

Trying using this code and it should work.

 

Create a point to draw the the section line

 

Dim oTG As TransientGeometry

oTG = ThisApplication.TransientGeometry

 

oPoint5 = oTG.CreatePoint2d(-100, 60)
oPoint6 = oTG.CreatePoint2d(100, 60)

 

    oDrawingSketch = oBaseView.Sketches.Add
    oDrawingSketch.Edit
    oSketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPoint5, oPoint6)
    oDrawingSketch.ExitEdit

 

oSectionView = oSheet.DrawingViews.AddSectionView(oBaseView, oDrawingSketch, oPoint7, kHiddenLineremovedDrawingViewStyle,DrawingViewScale)

 


For the coordinates of the points 5 and 6 choose according to your darwing and play around with it to get the excat position.

 

Hope this helps you.

 

Thanks

Shiva.

Message 108 of 133
karram
in reply to: Eddie.trooper

Hello shiva, You have any program in I-Logic or VBA for Auto creation of Drawing views, Auto dimensions, Sectional view etc. If you had means pls send the code and detais Thanks, Karthick ##################################################################################### This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system. Thank You. #####################################################################################
Message 109 of 133
mehatfie
in reply to: mehatfie

Hi Karthick,

For your Section view, why don't you use the top and bottom lines of the view, then find the midpoints to insert into the SectionView function


Shiva,

I'm not quite positive what you mean by detect, can you further explain your situation

Thanks
Mitch
Message 110 of 133
mehatfie
in reply to: mehatfie

Karthick,

 

Instead of using the circle, try using the MidPoint as your Point Intent to enter into the Section view function. This should Make things a little easier

 

 

Shiva,

 

It might be easier to understand what you're trying to explain with some code or screen shot. If you'd like to provide some.

 

 

Regards

Mitch

Message 111 of 133
karram
in reply to: mehatfie

hello,

 

                 in ilogic how can i create sectional views in drawing sheets and detail view also for appropriate positions.

 

Thanks

karthick

Message 112 of 133
mehatfie
in reply to: karram

Hi Karthick,

 

In my original code I had a function that created Detail Views. If you look there then you should be able to use most of the function and I'm sure you should be able to insert the Section View Code from the API and make a function for that as well from the bases of the code.

 

Regards
Mitch

Message 113 of 133
karram
in reply to: mehatfie

 

           I am new for the creation of section view and detail  in i-logic. So i need more clarification about the code. I am not able understand your orginal code, its bit of confusing, because you used the your inventor model parameter like (inlet flange, outlet flage). So there iam not getting clearly. So pls guide me.

 

Thanks

Karthick

Message 114 of 133
mehatfie
in reply to: karram

Hi Karthick, 

 

I believe the most helpful thing I can teach you is how to use the Inventor's API if you do not know how to do so.

 

If you go to the "Tools" tab and click on the "VBA Editor" Button,  a new window wwill pop up in Inventor. From here, press F2 and the object browser should open for the API.

 

Scroll through the classes in the side bar until you come to "DrawingViews," in the main window, a list should come up with all of the possible options that may be used from DrawingViews. You are looking for "AddDetailView." If you select this option by highlighting it and proceed to press F!, a new window will appear with the help options for this function. A description of everything required to use this function will appear here.

 

Let me know if you need further clarification

 

 

Regards

Mitch

Message 115 of 133
karram
in reply to: mehatfie

Hello,

 

1. I create sectional views in Assembly model.
2. In that how to get edge name in assembly model its very confusing to me.
3. Is there any tool, to displays the edge name or sketch name in inventor to make VBA code.
For example: Some of sample VBA program, they use( sketchline 1, drawcurve 1..).how to get these name in existing model.

 

Thanks
karthick

Message 116 of 133
mehatfie
in reply to: karram

Hi Karthick

 

I believe what you're seeing is code that they create the sketchline in. Since they are creating it, you can name it and keep track of this line if you want to use it in further code. The drawcurve is probably a similar concept.

 

In my code I created a search engine, where you enter the length of the line, orientation, and other descriptive comments to specify which line you are looking for. If you look back to my descrpition of the CreateLinearDimension, you should be able to understand the type of search engine you'd need to create. You can also refer to the code file for reference in creating your own.

 

Regards

Mitch

Message 117 of 133
ChristinaForest
in reply to: karram

Hi all!

 

I just want to create a automatic isoview at my first page of my assembly who are at my second page, all with ilogic, anybody abble to help me 🙂

 

Thanks!

Message 118 of 133
shirazbj
in reply to: karram

Hi Mitch,

 

Great work.

 

I am trying to follow you to figure out how to dimensioning a circle.

 

Peter

 

Message 119 of 133
wr.butler
in reply to: karram

Hi,

I'm new to all this Ilogic programming and tried your example files provided but have the following error when runnig it:

 

ERROR MESSAGE

Error in rule: Drawing Automation, in document: Hang_Beam.iam

Paramètre incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

MORE INFO

System.ArgumentException: Paramètre incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

   at Inventor.Documents.Add(DocumentTypeEnum DocumentType, String TemplateFileName, Boolean CreateVisible)

   at LmiRuleScript.CreateDrawing_PlaceViews(String PartNumber, Double DrawingViewScale, String ViewsToPlace, Boolean AssemblyDrawing, DrawingView& oBaseView, DrawingView& oView2, DrawingView& oView3, DrawingView& oView4)

   at LmiRuleScript.Main()

   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Can you help me?

 

Actually, what I would like to have is a command button in my ipt and iam files to generate an automatic drawing with the views, proper scaling of the views depending on the sheet size, automatic centerlines, and parts list. All this to minimize the number of clics!! BTW I use Inventor Pro and Vault 2014

 

Thanks,

Message 120 of 133
kylenilsen
in reply to: karram

I get the same error message as above commentor.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report