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
44460 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 21 of 133
mrattray
in reply to: mehatfie

You can't just shove an extra enum in there. He was probably trying to do the same thing as you and then found out he couldn't. He should have deleted that dingle berry out before publishing it.

 

Remember that everyone on the internet knows everything and if someone can post on a forum everything he does is perfect.Smiley Happy

Mike (not Matt) Rattray

Message 22 of 133
mehatfie
in reply to: mrattray

Unfortunate that it's not that easy Smiley Wink

 

Now I'm trying to save the drawing as I'm trying to run the rules inside of my template automatically

 

I need to find out how to save the document and the closing it will be pretty much the same I assume

Message 23 of 133
mrattray
in reply to: mehatfie

ThisDoc.Document.Close

 This will save and close the document.

ThisDoc.Document.Close(False)

 This will close without saving.

 

ThisDoc.Document.Save

 This will save without closing.

 

 

ThisDoc.Document.SaveAs(filePath & "\" & fileName & ".idw" , False)

 This does a save-as without closing. This is copy/pasted out of a sub that I'm using it in where filePath and fileName are strings that hold the obvious information. In other words there are earlier in the code several lines like the following:

Dim filePath As String
Dim fileName As String

filePatch = "C:\temp"
fileName = "temp"

 You could also just replace that garble with a regular line of text like: "C:\temp\temp.idw"

I don;t remember what he False is for and it's time for me to go home.

 

Mike (not Matt) Rattray

Message 24 of 133
mehatfie
in reply to: mrattray

I figured out how to Close the document which is similar to the "ThisDoc" command except it's not ThisDoc as the rule is being run in the assembly but I want to control the Drawing Document which technically doesn't exist yet as it hasn't been saved.

 

I learned to use the Object Browser to a little more extent, it looks like I have to use this

"DrawingDocument.Save2([SaveDependents As Boolean = True], [DocumentsToSave])"

 

I can't figure out what this DocumentsToSave means

 

Thanks for your help though

Mitch

Message 25 of 133
mehatfie
in reply to: mehatfie

I've now Saved the Document by doing a SaveAs instead as I can actually figure out how to do this, and once I open this document shortly after the SaveAs my rules trigger. So everything seems to being flowing as I want it to unless there is a better way of coding it.

 

All I need now is to figure out how to get those 4 options set in the view

 

Thanks

Mitch

Message 26 of 133
mehatfie
in reply to: mehatfie

I'm not very good at posting my questions in one message...

 

As I am waiting to figure out how to set those view options, I'm looking into attempting to dimension the views.

 

Looking at the API, I had trouble trying to use the "Add Linear" for "GeneralDimensions". I'm sure that I filled out one of the sections wrong in the brackets but I can't figure out which one. I tried to use "kStartPointIntent" and "kEndPointIntent", but I don't understand how they would know what to select.

 

Moving on after trying that, I'm now looking at the "GetRetrievableDimensions" in "GeneralDimensions". I do not know what the code wants from me when it asks for the "ModelObject"

 

I inserted "Add" into this location where it asks for "ModelObject" and I get this error which I'm assuming means that I'm using the API improperly

 

 

Error in rule: Rule21, in document: Rect_Transition_Chute_Generator.iam (MASTER iLogic Assembly)

Public member 'DrawingDimensions' on type '_DocumentClass' not found.

 

Thanks Again

Mitch

Message 27 of 133
MjDeck
in reply to: mehatfie

Mitch,

 About the options to create the view initially:

The Level of Detail will be taken directly from your model document.  If you activate the LOD that you want before running the rule, that's the LOD that will be shown in the drawing views.

 You can add the View Representation name to the function to create the base view:

oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, 3/16,kFrontViewOrientation, kHiddenLineDrawingViewStyle, "Default")

It looks like the API doesn't provide a way to specify the options for reference components when you create a view:

Line Style = "As Parts"

Hidden Line Calculation = "All Bodies"
DrawingViewReferenceData.png

 

About the dimension error: are you looking for a DrawingDimensions object directly on the Document?  It's on the Sheet instead:

oSheet.DrawingDimensions

 

 Again, I would recommend using VBA or VB.NET to develop this code.  It might take you a while to get started, but it will save you time in the long run.


Mike Deck
Software Developer
Autodesk, Inc.

Message 28 of 133
mehatfie
in reply to: MjDeck

Thank for the help Mike, I'll give it a shot and see if I can find a way around those options.

 

I will try to do it in VBA, the only issue is that I don't have "time" to learn the code in depth in order to do what I like. But, nop harm in giving it a shot.

 

Thanks

Mitch

Message 29 of 133
mehatfie
in reply to: MjDeck

Hello and welcome to Monday Smiley Tongue

 

In doing some more reseach and making the changes that Mike suggested with a few extras of my own, the code and drawing have improved.

 

With the research I have found a way to place dimensions but the suggested way is only possible by manually pre-selecting the line then running the vba code. This worked and placed the dimension, and I understand how to manipulate this code to change the type of dimension as well as where it is placed.

 

But as you know, I do not wish to manually pre-select the line. Through more looking around a found a user who was looking to apply centerlines in views (which I will also need to do later on).

 

One of the suggested methods is to use the "ModelEdge" object. I looked in the object browser and did not find anything their myself but I could be missing something.

 

To me, this sounds to be exactly what I'm looking for. If I can pre-select the line by programmically calling the model edge I wish to dimension, I can run this code that dimensions the selected line.

 

You can find the code so far attached

 

The commented line "oCurve = oDrawDoc.SelectSet(1).Parent" is what was used to get the manually selected line

 

Here is the Centerline forum, Message 13 is the reference:

 

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

 

Thanks
Mitch 

Message 30 of 133
mehatfie
in reply to: mehatfie

I just realized some numbers in that code may look a little weird.

 

I use a drawing template that I've put existing codes into like this one which resizes the view and places them where I'd like.

 

I've also tried this as a test but it does not work and an error comes up once it hits this portion of code. See attached "Test Code" 

 

Thanks Again

Mitch

Message 31 of 133
mehatfie
in reply to: mehatfie

I got the code to work as a test, except for one problem.... no dimension is placed

 

I wrote the attached code in VBA and it works, but when I adjust it for iLogic format it does not.

 

Is there a reason as to why this does not work? is it not supported in iLogic?

 

Thanks

Mitch

Message 32 of 133
MjDeck
in reply to: mehatfie

Mitch,
 It should work if you add these lines at the top of the iLogic rule:


Imports Inventor.PointIntentEnum
Imports Inventor.DimensionTypeEnum


Lines like this are required whenever you create rules from VBA code that contains Inventor constants that start with a "k", such as kStartPointIntent.  Search the Inventor API help for the constant name, and it should show you an Enum type.


Mike Deck
Software Developer
Autodesk, Inc.

Message 33 of 133
mehatfie
in reply to: MjDeck

Thank you Mike, this worked and now I know where I can go if this happens again.

 

Since this has worked for me, I have an idea of how I'm going to go about dimensioning the drawing, but I have a few questions before I start to write the code.

 

Method:

 

Im going to get the number of DrawingCurves within the view and create a loop that stops when it reaches this number. I will continually increase the index by 1 and feed this number into

 

oSheet2.DrawingViews(1).DrawingCurves.Item(Index)

 

I will do this to find the highest curve in the view and the lowest as this will be my 2 flanges. I will also use these 2 curves to get the overall height by creating a dimension between the 2.

 

Questions:

 

Is there a way to get the length of the DrawingCurve? I know what the dimension should be do to my model parameters, and want to use this as a check in order to place the dimensions I want as I cycle through the index.

 

Is there a way to tell if the dimension will fit centered within it's annotation, this will be helpfull for deciding if I'm placing the dimenion text as an extension outside the arrows, or within them.

 

I have tried "oSheet.DrawingDimension.DimensionLine" to attempt to get the length of the dimension, this did not work as an error occured saying "DimensionLine" is not found on the sheet. You have addressed this issue earlier for me as per something being part of the document or the sheet. Is there a way for me to tell beforehand without trial and error?

 

Last one, I am going to do a little fiddling around with this one as I'm sure it's easy. I want to read the Point data from the StartPointIntent and EndPointIntent so I can add 2 for example to offset the dimension from the view.

 

I have tried "oSheet2.DrawingViews(1).DrawingCurveSegments.Count" and attempted to output this to a MessageBox but the "Overload resolution failed..." error came up and with my past experiences I believe this means I'm attempting to put the wrong type of variable into the MessageBox. I looked into the "Count" and found that this is a "Long" variable type which I believe is a String?

 

 

Thank you for all your help!!!  And please ask if you need anymore information

Mitch

 

 

 

 

Message 34 of 133
mehatfie
in reply to: MjDeck

Hi Mike,

 

I have answered most of my mine questions at this point and in the process of writting my code.

 

In order to make it more effiecient, I am trying to Return a value from a sub but I get the error:

 

"Error on Line 44 : 'Return' statement in a Sub or a Set cannot return a value."

 

Is there any way around this in ilogic?

 

Thanks

Mitch

Message 35 of 133
MjDeck
in reply to: mehatfie

Mitch,
 I'm glad to hear that you found answers to most of your questions.

To return a value, you have to create a Function instead of a Sub.  Here's a very simple example:

 

Function Average(a As Double, b As Double) As Double

  Return (a + b) / 2

End Function

 

Sample code to call it:

 

av = Average(4.5, 6.2)

 

If that doesn't fit what you're doing, please attach your rule (or at least the part of it that gets the compile error).


Mike Deck
Software Developer
Autodesk, Inc.

Message 36 of 133
mehatfie
in reply to: MjDeck

I assume this works for Strings as well in which case it should work fine.

 

Does iLogic accept doing "Pass by Reference" or just by Value? And if so how would I go about doing this.

 

To my knowledge, if I remember correctly, Pass by Reference entails putting a "&" where the "As" is placed

 

Pass By Reference:

test1 & Double

 

Pass By Value:

test1 As Double

 

 

Thanks Again

Mitch

Message 37 of 133
MjDeck
in reply to: mehatfie

Mitch,

 iLogic uses VB.NET.  VB.NET supports passing arguments by reference with the ByRef keyword.  (& is used in C++).  An example with ByRef:

Function RemoveTrailingBackslashes(ByRef strX As String) As Boolean
  Dim hadBackslash As Boolean = False
  While (strX.EndsWith("\"))
    hadBackslash = True
    strX = strX.Substring(0, strX.Length-1)
  End While
  Return hadBackslash
End Function

 

Here's some documentation: http://msdn.microsoft.com/en-us/library/c84t73c2.aspx


Mike Deck
Software Developer
Autodesk, Inc.

Message 38 of 133
mehatfie
in reply to: MjDeck

Mike,

 

I changed the Sub to a Function as you have shown me and I'm now attempting to run a test case through it.

 

Attached you'll find a portion of the code that is not working in the Function.

 

I cannot set the variable "oPartDoc"

 

You can see that I have Message Boxes set up to test where it fails, and everything works fine up until that point.

 

The Error is as Follows:

 

Error in rule: Rule21, in document: Rect_Transition_Chute_Generator.iam (MASTER iLogic Assembly)

Unable to cast object of type 'System.String' to type 'Inventor.Document'.

 

 

Changing the code to:

 

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:    1527 StartFragment:     314 EndFragment:    1495 StartSelection: 314 EndSelection:     314
SyntaxEditor Code Snippet

oPartDoc=ThisApplication.Documents(oPartPath+"\"+PartNumber+".iam")

 

Gives me this Error which doesn't make any sense due to no Integer being involved

 

Error in rule: Rule21, in document: Rect_Transition_Chute_Generator.iam (MASTER iLogic Assembly)

Conversion from string "C:\Vault_Work\PROJECTS\iLogic Pa" to type 'Integer' is not valid.

 

Thanks

Mitch

 

Message 39 of 133
MjDeck
in reply to: mehatfie

On this line:
oPartDoc = oPartPath + "\" + PartNumber + ".iam"

You're putting together an assembly file name, but assigning it to a part document.  Do you want to open an assembly?  Or is it already open and you just want to get the document?


Mike Deck
Software Developer
Autodesk, Inc.

Message 40 of 133
mrattray
in reply to: mehatfie

Conversion from string "C:\Vault_Work\PROJECTS\iLogic Pa" to type 'Integer' is not valid.

 

This is because you're using a + instead of an &. Use &'s to combine strings. Also, what the other Mike said.

 

It's giving you a conversion error because it sees the +'s and thinks you're trying to do math. If you had numbers stored as strings then this would work. iLogic would convert the strings to numbers and add them up, but it fails because they're not numbers.

Mike (not Matt) Rattray

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

Post to forums  

Autodesk Design & Make Report