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
43381 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 81 of 133
mehatfie
in reply to: mehatfie

All,

 

Attached you'll find the FULL DRAWING CODE as well as a photo of what this code produces.

 *This code was created in run directly in iLogic

 

I have Fully commented it to make it easier to understand and have created what is probably a page of comments at the top of the code describing how to use each Function.

 

This is on and off research throughout 2 months of searching through threads and finding different codes to learn from.

 

Except now it's ALL IN ONE PLACE on this thread!!!

 

Keep in mind that my code is run through an assembly which is also fully parameter based and runs on multiple iLogic rules. This is why all of my dimensions are Names as they are parameters being passed into the sub.

 

The code places all of the views at a single point when they are created. These views are then moved based on a code in the Drawing Template. This code is not complete but I have attached the one I use right now for reference. Also keep in mind that Parameters are used here which is why you might see names where numbers or Letters should be.

 

I hope this helps you while your learning the code and API. Here are some other threads I used:

 

http://forums.autodesk.com/t5/forums/forumtopicprintpage/board-id/120/message-id/37402/print-single-...

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/dimension-sheet-metal-drawing/td-p/183...

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Add-Centerlines-through-VBA/td-p/30897...

 

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Drawing-Automation-with-VBA/td-p/29835...

 

http://forums.autodesk.com/autodesk/attachments/autodesk/78/410518/2/viewcolor.txt

 

 

 

Please feel free to ask any questions while I am still available

Kudo's if this helps you!

 

Thanks for all Your Help!

Mitch

 

Message 82 of 133
MegaJerk
in reply to: mehatfie

This is really awesome! Thanks a lot of sharing your finished product, as it should come in handy for pushing automation to higher (sexier) levels. It's a wonderful thing to see this all come together (more so for you I'm sure!). 

Congrats!  



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 83 of 133
mehatfie
in reply to: MegaJerk

I'm going to post a revision of the code as I've added a few more subs for ordinate dimensions and centerlines as well as changed a few things.

 

But first I have a question, if you see the attached photos, I am trying to place a Hole Thread Note.

 

I've tried using different intent points or just the drawing curve while adding the note, but I always end up getting the "Wrong" note as the leader is on the other side of the circle

 

Thanks

Mitch

Message 84 of 133
LouisGuillemette
in reply to: mehatfie

I am using an ilogic rule to make center lines with an event trigger (before saving document)

 

ActiveSheet.View("VIEW1").View.SetAutomatedCenterlineSettings()
On Error Resume Next

 

ActiveSheet.View("VIEW2").View.SetAutomatedCenterlineSettings()
On Error Resume Next

ActiveSheet.View("VIEW3").View.SetAutomatedCenterlineSettings()
On Error Resume Next

 

Is there a better way to do this?  The obvious problem is if theres is au 4th view...

Also, because of automated centerlines default settings, the only centerlines beeing drawn are the one where you see a hole function as a circle.  No center lines are being drawn on cylindcrical shapes or patterns,

Is there a way to set the automated centerlines options so that they remain a certain way and not always revert to only drawing center lines on a hole top view?

 

Thank you

Louis G

Message 85 of 133
mehatfie
in reply to: LouisGuillemette

Hi Louis,

 

Unfortunately I currently do not have access to Inventor to fully assist you, but the following code should be something like what you're looking for. A few minor tweeks might be needed.

 

For the centerline settings, there is a way to change this programmically with the API, but as I said, I do not currently have access to Inventor.

 

>>> If you are using a template drawing, you can set the default Automated Centerlines but accessing "Document Settings" under the "Manage" tab. I do not remember how to direct you farther from here, but once you set up the centerline's default options, these centerlines will always be placed whenever you run "SetAutomatedCenterlineSettings"

 

Cheers

Mitch

 

'		Dim oNumView As DrawingView
'		Dim ViewCount As Integer
'		Dim StartCount As Integer
'		
'		ViewCount = 0
'		StartCount = 0
'////////////////////////////////   Counts the number of drawing views on the sheet
'		For Each oNumView In ActiveSheet.DrawingViews
'			ViewCount = ViewCount + 1
'		Next
'//////////////////////////////////// Places Centerlines on all of the drawing views
'		For StartCount = 1 To ViewCount
'			ActiveSheet.DrawingViews(StartCount).SetAutomatedCenterlineSettings()
'		Next
 
Message 86 of 133
mrattray
in reply to: mehatfie

Just out of curiosity, why do you do it with two loops? Why not just set the centerlines in the for each loop?

Also, if you change the names of your views from default or if you delete views I think the code will fail. It will look for view 4 which no longer exists due to either now being view c or becuase it was deleted and return an error.

 

I think this will work better, although I'm much too lazy today to test it.

 

dim oview as drawingview
dim oviews as drawingviews

views = activesheet.drawingviews

for each oview in oviews
ActiveSheet.DrawingViews(oview.name).SetAutomatedCenterlineSettings()
next

 

Mike (not Matt) Rattray

Message 87 of 133
LouisGuillemette
in reply to: mehatfie

Hi

It finally works!

Thank you all for your help.

 

Here is the code:


Public Sub LignesAxes()

Dim oNumView As DrawingView
Dim ViewCount As Integer
Dim StartCount As Integer
Dim oview As DrawingView

StartCount = 0

'number of drawing views
ViewCount = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews.Count

'define collection of views objects
Set oviews = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews

' Places Centerlines on all of the drawing views
      For StartCount = 1 To ViewCount
           oviews.Item(StartCount).SetAutomatedCenterlineSettings
       Next
End Sub

 

 

Message 88 of 133
mehatfie
in reply to: mrattray

Hi mrattray,

 

I initially used a single loop to do a lot of my tasks, but for some reason the program would fail as it would not search correctly through every single object. By doing it this way with 2 loops, I am telling the program to access that specific object through it's index and perform the neccessary tasks.

 

I believe you're also talking about the function, where I have the filler views as parameters. You are right that the program will not work if these are removed. These are just place holders as all parameters that consist in the function need to be filled in for the program to run. A previous parameter in that same function tells it what views to use, and the rest of the filler views are not taken into account.

 

Sorry for the long delay

 

Mitch

Message 89 of 133
karram
in reply to: mehatfie

Hello,

 

              Your codes are really awsome. Could you attach the inventor assembly file releated to this code. Its very helpful for me.

 

BR.

Karthick

Message 90 of 133
mehatfie
in reply to: karram

Hi Karthick,

 

Unfortunately I cannot provide you with the files themselves do to company policies, but can assist you with any further questions you may have.

 

I may be able to provide screenshots as well for specific scenarios

 

Thanks

Mitch

Message 91 of 133
karram
in reply to: mehatfie

Hello,

 

            Find the attached assembly. And kindly make a I-Logic code for this assembly, include Generation of drawing views, auto dimensions, Detail views etc... its very helpful for me. please.

 

BR.

Karthick

Message 92 of 133
mrattray
in reply to: karram

I've got some assemblies for you, too, Mitch... Smiley Very Happy

Mike (not Matt) Rattray

Message 93 of 133
karram
in reply to: mrattray

Okay, 

 

             Kindly please send the assemblies with releated I-Logic Codes.

             Its very helpful for me.

 

Thanks

Karthick

Message 94 of 133
mehatfie
in reply to: karram

Good Morning,

 

At this time I won't be able to go through your assemblies and create the drawings, as I am busy at the moment from just returning to work. 

 

I took a look at your assembly and can explain some processes that will make it easier to transfer to drawings through iLogic.

 

 

 

If you create a parametric model (eg. a model that is fully based on parameters), you can enter these parameters into the code rather than constantly changing an updating value through hardcode.

 

When programing the drawings, nothing is "automatic," the code that you write must compensate for ANY and ALL scenarios that occur. I'm sure that your model will be changing in the end, as this is the benefit of creating automated drawings. A scenario may consist of, for a basic example, removing a piece of the assembly by turning it on or off, or adding a piece etc.. The placement of dimensions and such will be based off of these scenarios and are easily controlled through  If / Else statements.

 

That raises another questions, what is your previous experience with programming? 

 

It is also beneficial to have a parameter running in the background which tells your program that a certain piece is turned on.

 

For Example,

 

If  "Chute Side" = True Then

 

     // Run these dimensions //

 

End If

 

 

Again, the coding itself takes some time, which I am limited to at the moment, but I can do my best to take you through the process with these replies and answer any questions. If you go through these processes and provide me with the files as you have, I'm sure I could take a quick look and walk you through. 

 

I am only recently returning to my project as well and have quite a few improvements which I cannot get to at the moment either, but I'm sure I can assist you both in the way stated above.

 

Thanks

Mitch

 

Message 95 of 133
karram
in reply to: mehatfie

Hello,

 

              Thanks for your reply.

               1. My Experience 2.5 years programmer.

               2. In that assembly no parameter define.

               3. Assembly is very simple only, if you have a time. Pls define the I-Logic codes.

               4. Otherwise  if you had any sample Assembly model with i logic code. pls send it.

 

BR

karthick

Message 96 of 133
mehatfie
in reply to: karram

Hi Karthick,

 

You actually have more experience than myself with programming so you should be pretty good at starting off. I realize that there are no parameters in the assembly you provided, but instead I had stated that parameters should be ADDED to make the iLogic programming simpler and more understandable (use descriptive naming for the parameters).

 

I realize the assembly is simple, but programming it for automated conversion into a drawing would still take some time and thought, at which this moment I do not have the ability to provide.

 

Again, I apologize that I cannot provide my assembly do to company policies, and I cannot make a new assembly either do to the same time constrants as stated before.

 

At this time I can provide you with support only, as taking a quick look and typing this does not take me a great deal of time.

 

Once again I aplogize for my time issues

 

 

Thanks

Mitch

Message 97 of 133
mehatfie
in reply to: karram

Karthick,

 

This is the best I could do with the time I had left over lunch, please feel free to ask any questions if necessary.

 

Note that you will need to change something in the Rule based on where you save the files, you'll need to put the file path into the code which is in the second CreateDrawing function.

 

The views will not be placed into the necessary locations either, as I had a rule in the drawing template itself which organized the views.

 

All of your files should be in the same location (ie. all parts, assembly files)

 

This should be a basic start to get you going on how things work within the function.

 

 

Hope it helps

Mitch

Message 98 of 133
karram
in reply to: mehatfie

Hello,

             Thanks for your reply.
             1. First of all, this kind of programming like(Auto generation of drawing, auto dimensions etc)  iam fresher.


              2. Here i attached the I-Logic codes & Screen shot for error message box.

 

'/// Number values in iLogic are in cm, cm to inch conversion -> divide by 2.54
  
  CreateLinearDimension (Assem_DrawingDoc, oBaseView, 5*DrawingViewScale/2.54, "Vertical", -2, "Left", False)
  
  
  'Place Top_Rack View
  TopRackView = CreateDrawing_PlaceViews ("Top_Rack", DrawingViewScale, "Top", False, oTopRackView, oView2, oView3, oView4)
  
  CreateLinearDimension (TopRackView, oTopRackView, 6*DrawingViewScale/2.54, "Vertical", 2, "Right", False)

           3. For create Linear dimension code, i just copied and the paste into i-logic codes. Dimensions are not creates.

 

           4. Understanding of create Linear dimensions is very difficult for me.

           5. Auto creation of Drawing views is now OK, only thing is creation of dimensions.

 

             Please guide me to create the dimensions.

 

Thanks,

Karthick

 

 

Message 99 of 133
mehatfie
in reply to: karram

Hi Karthick,

 

What iLogic is doing is looking through the specified Drawing View and searching for a Line of the specified size. The Line is placed on the drawing page and has scaled dimensions appropriately (ie. if the model size was 5" and you've scaled the view to 1/2, you should tell the program to search for a 2.5" line). This is why we enter this formula into the dimension length section of the linear dimension code (5*DrawingViewScale/2.54). I am searching to dimension the left side of your model which is 5cm (50mm), but the Drawing (.idw) sheet dimensions lines according to inches (if you have selected an imperial DWG sheet), so we must convert cm to inches by dividing by 2.54. We multiply by the DrawingViewScale which is defined by you earlier in the code, in order to tell the program what we have scaled the view by and therefore to search for this scaled dimension. 

 

Now that I think of it, this is probably where the issue is occuring. I remember when you sent me your files that you were using metric parts, I'm assuming that you're now using metric drawing files as well (.idw). I have only used imperial drawing files previously.

--->>> My thinking is (as stated in my first paragraph) that the drawing is now thinking in metric (cm) instead of imperial (inches) like it was for me. I am not positive of the units, so you may have to play around a bit (eg. convert the 5cm in the CreateLinearDimension into milimeters or meters), so that the drawing will be able to find the Line you're looking for.

 

 

Did you create the projected view? Or was it created with the Drawing Automation?

 

If it was placed by the code, there may be a small issue which can easily be fixed. The iLogic code places the views in the drawing according to the specified orientation, we've specified this to be "Top." If you open a drawing file (.idw) and press "Base" as if you were placing a view, look on the right hand side of the screen that pops up where you'll see "Orientation." These predefined names are what you can enter into the iLogic code in order to place the orientation you desire. Try placing your model to see which way it is oriented, you can change this by manipulating the view orientations of that View Cube in your 3D model. You must be placing these views in accordance to the dimension you wish to find (and place) on the view, or else iLogic will never be able to find it since it does not exist in the view you've told it to look for.

 

 

//// The Error Message

 

This error message will become VERY familiar to you as you go through creating and debugging your code. What I have found it to mean (in simple terms), is it cannot find the dimension you have told it to look for. Simply, you've told the code to look in ______ view and find a Line of ____ size, if it cannot find this, the error code you show will come up. This should be the meaning of this error message most of the time it appears.

 

 

//// Understanding of CreateLinearDimensions

 

 

 

----- Informationand options about function ------

 

'CreateLinearDimension (oDrawingDoc, oDrawingView, DimensionLength, DirectionOfDim, OffsetDistance, DimensionLocation, ReferencedDim)


'WHAT IT DOES: Used to place linear dimensions on Horizontal or Vertical Lines
'CODE RETURNS: The Dimension for use in of Functions such as Aligning Text
'oDrawingDoc: The Drawing Document which the View exists in
'oDrawingView: The View you which to place the dimension on
'DimensionLength: The length of the Curve you want to dimension (Mine are Driven by a parameter in the Model)
'DirectionOfDim: A String which specifies the orientation of the line to look for
'OPTIONS: ("Vertical", "Horizontal")
'OffsetDistance: A number which specifies the distance to Offset the text from the line
'(Must be negative Or positive based on your knowledge of where the line is (ie. "-" if Left and "+" if Right))
'Or you can place the dimension inside the view by choosing the appropriate sign
'DimensionLocation: Multiple lines can have the same length, this String specifies which line to choose. Closest to the given side
'OPTIONS: ("Top", "Bottom", "Right", "Left")
'ReferenceDim: True or False as to whether this dimension is to be a referenced dimension
'(This is selects between 2 Styles previously set up in the Drawing Template)

 

 

 

--- Example Code ----

 

'Place Top_Rack View
TopRackView = CreateDrawing_PlaceViews ("Top_Rack", DrawingViewScale, "Top", False, oTopRackView, oView2, oView3, oView4)

CreateLinearDimension (TopRackView, oTopRackView, 6*DrawingViewScale/2.54, "Vertical", 2, "Right", False)

 

 

----- Explanation ----

 

For this function, you've created and named a view when you placed it (ie. "TopRackView ="), and now can tell the iLogic code you wish to search in this view by simply entering "TopRackView."

 

In the code shown above, the "TopRackView =" should actually be removed (I apologize that this was my own mistake, I am only starting back into this program). By setting something "=" to the CreateDrawing_PlaceViews function, you are specifying a document, this has already been previously done in the code by this line:

 

----

Assem_DrawingDoc = CreateDrawing_PlaceViews (AssemblyDocName, DrawingViewScale, "Right_Project", True, oBaseView, oRightSideView, oProjectView, oView4)

----

 

Therefore the code should read:

 

----

'Place Top_Rack View
CreateDrawing_PlaceViews ("Top_Rack", DrawingViewScale, "Top", False, oTopRackView, oView2, oView3, oView4)

CreateLinearDimension (Assem_DrawingDoc, oTopRackView, 6*DrawingViewScale/2.54, "Vertical", 2, "Right", False)

----

 

In CreateDrawing_PlaceViews, we've specified that we only wish to create the "Top" view (See function description in the beginning of the Drawing Automation code for more options). Therefore, only the oView1 space will be used, in which case we've specified we want to title this view "oTopRackView." You can now access this view on the drawing at anytime throughout the "Sub Main()" function by refering to "oTopRackView."

 

Let's look back at the base code for CreateLinearDimension:

 

----

CreateLinearDimension (oDrawingDoc, oDrawingView, DimensionLength, DirectionOfDim, OffsetDistance, DimensionLocation, ReferencedDim)

 

----

 

We've now specified the Drawing Document (oDrawingDoc:  Assem_DrawingDoc), as well as the View we wish to place the view in (oDrawingView:  oTopRackView), the rest of the code is to specify the dimension itself.

 

DimensionLength: The length of the dimension you wish to locate in the drawing (must be converted to use the drawings (.idw) length by multiplying by DrawingViewScale and other methods appropriately.

 

DirectionofDim: This tells iLogic which orientation the line is in, so it narrows down its search (ie. if the Line you are looking for runs vertically, type "Vertical," if it runs horizontally type "Horizontal")

 

*** Note that text Strings must be wrapped in " " quotations with spelling and capitals also taken into account

 

OffsetDistance: The distance you want the dimension to be placed away from the line it was taken from (ie. 2" to the left = -2)

 

DimensionLocation: In some cases, there may be 2 lines that are very similar within the view, in this case, you can specify closer to which side you want to take it from (ie. "Right")

 

 

***** Important May Need Change ******

 

ReferencedDim: I had made a new style in my drawing template to incorporate referenced dimensions. If you don't know what a referenced dimension is, you do not have to worry about this and I believe you can simply place False here everytime, the code should still take the default dimension style in your drawing template everytime. My referenced dimension style simply placed ( ) Brackets around the dimension if I put True here.

 

^^^ If you would like this, I can take you through the process to add this to your drawing template

 

 

 

 

 

I believe that answers all your questions for now, let me know if this helped or if you have any others.

 

MRattray, feel free to ask any further questions you may have as well, I can try to assist you with your assemblies if you have questions.

 

Thanks

Mitch

 

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

Thanks a lot mitch fro your replys. The code works, but when i try putting the same code in the assembly drawing it fails again with the same error, also when i try to dimension the distance between centers of two holes the code fails again. I just want to knwo is there any other way of doing the same?

 

Thanks,

Shiva

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

Post to forums  

Autodesk Design & Make Report