Ilogic - create drawnings of all parts from an assembly

Ilogic - create drawnings of all parts from an assembly

m.rymut
Advocate Advocate
7,781 Views
21 Replies
Message 1 of 22

Ilogic - create drawnings of all parts from an assembly

m.rymut
Advocate
Advocate

Hi

Is it possible to use ilogic to create dwg drawnings of all the parts in an assembly?

So if i have an assembly with 10 parts, ilogic rule will make 10 files of drawnings, one for each part.

I was wondering if it is possible, i found those 2 topics:

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/how-to-create-a-drawing-using-ilogic...

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-create-drawing-file-from-part...

 

In those 2 there is ilogic code that makes a drawning of a part but if i have an assembly that has 200 parts, then i would have to open each part and make a drawning, so i wonder if i could just open assembly and run ilogic rule that would make a drawning of each part. 

Something i was trying to achive was getting proper template and scale so that each part can fit inside the drawning, because some parts are small and some are big, so either the big ones are bigger than the drawning or the small ones are just too small.

I dont really need any dimensions or anything, just basic views, like a front view, top view and a right view.

 

 

0 Likes
Accepted solutions (2)
7,782 Views
21 Replies
Replies (21)
Message 2 of 22

basautomationservices
Advocate
Advocate

Yes this is possible. A few more things to consider:

1. Scaling and positioning of the views.

2. Orientation of the base view.

3. Naming/saving the files.

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 3 of 22

m.rymut
Advocate
Advocate
For scaling i was thinking about using custom iproperty named lenght, each of my parts have this custom iproperty and it corresponds to the biggest dimension, and i was thinking to make it so that the scale goes up with lenght of each part which is written in this custom iproperty, but i wasnt really able to make it work, since i am new to coding.
About positioning i was just thinking to make a front view in the middle, so height/2 and width/2 of the drawning, and then a top one in height *3/4 and width/2 and a right view in middle right so height/2 and width* 3/4.
2. I tought orientation would just correspond with the parts orientation.
3. Name of the .dwg files would be the same as the original part files, and the desitination save folder would just be a folder on desktop.
0 Likes
Message 4 of 22

basautomationservices
Advocate
Advocate

This thread should give you enough info to get what you need:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-auto-create-scaled-drawing-fr...

 

 

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


Message 5 of 22

WCrihfield
Mentor
Mentor

Just dropping another link here to a case I helped out with a few  years ago.  Just as another example of the 4 views and an example of the view scaling and orientation.  In case it might help out some.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 22

m.rymut
Advocate
Advocate

Thanks for the links, i will check them out and try to get the code working.

If i am successful then i will post the code in another reply.

0 Likes
Message 7 of 22

m.rymut
Advocate
Advocate

Hi again,

So i checked out topics that you linked and i found code that creates a drawning from a part and places views exacly how i want them to be placed.

I had to change some numbers and path of the template but after some try and error i got the code working.

Code is from this topic: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/automaticly-create-a-drawing-from-a-...

And i think its WCrihfield's code.

One thing is that i always got an error when trying long parts ( longer exacly than 1312 mm) when i was using measure instead of rangebox, but after i changed it to use rangebox then it started working properly.

Here is the code with changes:

 

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

If System.IO.File.Exists(ThisDoc.PathAndFileName(False) & ".idw") Then
	oOverWrite = MsgBox("A Drawing for this model already exists." & vbNewLine &
	"Do you want to over-write it?", vbYesNo + vbQuestion, "DRAWING EXISTS!")
	If oOverWrite = vbNo Then
		Return
	End If
End If

'The following line sends a full file name to Inventor's Clipboard, this can be used to automatically
'fill in a dialog that would normally pop-up asking for what model you want to place into your drawing.
'ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oFileName)


Dim oTPath As String = "C:\Users\Public\Documents\Autodesk\Inventor 2022\Templates\pl-PL"
Dim oTName As String = "Standard.idw"

Dim oDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTPath & "\" & oTName, True)
'oDDoc.SheetFormats.Item(1)

'Using Measure (instead of RangeBox)
'Dim oXDim As Long = Measure.ExtentsLength
'Dim oYDim As Long = Measure.ExtentsWidth
'Dim oZDim As Long = Measure.ExtentsHeight

''Using RangeBox for size
Dim oRangeBox As Box = oPDef.RangeBox
Dim oXDim As Long = (oRangeBox.MaxPoint.X - oRangeBox.MinPoint.X)
Dim oYDim As Long = (oRangeBox.MaxPoint.Y - oRangeBox.MinPoint.Y)
Dim oZDim As Long = (oRangeBox.MaxPoint.Z - oRangeBox.MinPoint.Z)

'MsgBox("RangeBox Size of Model = " & vbNewLine &
'oXDim & " along X Axis" & vbNewLine &
'oYDim & " along Y Axis" & vbNewLine &
'oZDim & " along Z Axis")

Dim oModelWidth As Long = MaxOfMany(oXDim, oYDim, oZDim)
Dim oModelHeight As Long = MinOfMany(oXDim, oYDim, oZDim)

'MsgBox("Longest Dim = " & oModelWidth & vbCrLf &
'"This will be used to calculate scale & view width in drawing.")

Dim oViewRotation As Double
Dim oViewOrientation As ViewOrientationTypeEnum
If oModelWidth = oXDim And oModelHeight = oYDim Then
	oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
	oViewRotation = 0
ElseIf oModelWidth = oXDim And oModelHeight = oZDim Then
	oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
	oViewRotation = 0
ElseIf oModelWidth = oYDim And oModelHeight = oXDim Then
	oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oYDim And oModelHeight = oZDim Then
	oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oXDim Then
	oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oYDim Then
	oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
	oViewRotation = 0
End If

'Get the size of the Active Sheet
Dim oSheetWidth As Double = oDDoc.ActiveSheet.Width
Dim oSheetHeight As Double = oDDoc.ActiveSheet.Height

'Get size of area within border available for views (used for scaling views)
Dim oSideBorderOffset As Double = 5
Dim oTopBottomBorderOffset As Double = 0.5
Dim oTitleBlockHeight As Double = 2.5
Dim oBorderWidth As Double = oSheetWidth-(oSideBorderOffset*2)
Dim oBorderHeight As Double = oSheetHeight - (oTopBottomBorderOffset * 2)
Dim oAreaAboveTitleBlock As Double = (oBorderHeight - oTopBottomBorderOffset) - oTitleBlockHeight

'Set view scale, based on model width
Dim oBViewScale As Double
If oModelWidth > (oBorderWidth/2) Then
	oBViewScale = ((oBorderWidth/2) / oModelWidth)
ElseIf oModelWidth < (oBorderWidth/2) Then
	oBViewScale = (oModelWidth / (oBorderWidth/2))
End If

inc = 1/32
oBViewScale = Round(Round(oBViewScale,5) / inc) * inc

'Try creating & placing each view at 1:1 scale, then scale to needed factor.
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oViews As DrawingViews = oDDoc.ActiveSheet.DrawingViews

Dim oFullScale As Double = 1
Dim oOriginPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oOriginPoint, oFullScale, _
oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

'Locations of view centerpoint columns & rows
Dim o1stColumn As Double = oSideBorderOffset + (oBorderWidth / 4)
Dim o2ndColumn As Double = oSideBorderOffset + ((oBorderWidth / 4) * 3)
Dim o1stRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + (oAreaAboveTitleBlock/4)
Dim o2ndRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + ((oAreaAboveTitleBlock/4)*3)

'Base View center point location
Dim oBaseViewLocation As Point2d = oTG.CreatePoint2d(o1stColumn, o1stRow)

'Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oBaseViewLocation, oBViewScale, _
'oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
oBaseView.Rotation = oViewRotation
oBaseView.Position = oBaseViewLocation
oBaseView.Scale = oBViewScale
oBaseView.ScaleString = RoundToFraction(oBViewScale,1/32,RoundingMethod.Round)
'oBaseView.Center = oBaseViewLocation
'oBaseView.RotateByAngle = 
oBaseView.IncludeMeshBodies = True
oBaseView.IncludeSurfaceBodies = True
'oBaseView.Top
'oBaseView.Height
'oBaseView.Left
'oBaseView.Width
oBaseView.Name = "BASE VIEW"
InventorVb.DocumentUpdate()
'MsgBox("Center Of View Is At:  " & oBaseView.Center.X & " , " & oBaseView.Center.Y)

'MsgBox("oBViewScale = " & oBaseView.ScaleString)


Dim oUpperViewInsPoint As Point2d = oTG.CreatePoint2d(o1stColumn, o2ndRow)
Dim oUpperView As DrawingView = oViews.AddProjectedView(oBaseView, oUpperViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oUpperView.Name = "UPPER VIEW"
oUpperView.IncludeMeshBodies = True
oUpperView.IncludeSurfaceBodies = True

Dim oRightViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o1stRow)
Dim oRightView As DrawingView = oViews.AddProjectedView(oBaseView, oRightViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oRightView.Name = "RIGHT VIEW"
oRightView.IncludeMeshBodies = True
oRightView.IncludeSurfaceBodies = True

'Dim oISOViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o2ndRow)
'Dim oISOView As DrawingView = oViews.AddProjectedView(oBaseView, oISOViewInsPoint, _
'DrawingViewStyleEnum.kShadedDrawingViewStyle)
'oISOView.Name = "ISO VIEW"
'oISOView.IncludeMeshBodies = True
'oISOView.IncludeSurfaceBodies = True


 Could you give me any tips on how to make it so i can run the code in anassembly and it will execute this code for every part? So that i can just run the rule in an assembly and i will get a drawning file of each part that is in the assembly?

Opening each part and running the code by hand is gonna take a lot of time.

Is there an easy way to achive that?

I have a rule that makes .stp file of every part in an assembly so i tried to swap the code that makes .stp for the code that makes .idw but it didnt work, so i guess there is something more to it. 

0 Likes
Message 8 of 22

WCrihfield
Mentor
Mentor

I have an idea.  If you want to be able to use this rule either from an active part document, or from an assembly, then I would make some changes at the beginning of this rule, as to how it identifies what document to target with the remainder of its code.  You will want to use just one main document variable, and stick with that variable, and don't use any other references like the term 'ThisDoc' or 'ThisApplication.ActiveDocument' anywhere else within the code after that point, to make sure it is working with the exact same document identified that the beginning of the rule.  Once we make these changes to that code, we will leave this rule alone.  Then if we need to use it in the context of an assembly, we can call it to run from another rule that is designed for iterating though an assembly, and provide a NameValueMap to the RunExternalRuleWithArguments method with the 'target document' for it to process.  Preparing this rule for receiving that 'target document' is part of this idea and can be done by accessing the RuleArguments resource.

 

I have attached the revised code with the proposed changes to this post as a Text file due to how long it is, and for convenience.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 22

WCrihfield
Mentor
Mentor

@m.rymut 

And here is an example of the other rule that you would use from an assembly, that will run that earlier rule on its referenced documents.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	For Each oRefDoc As Document In oADoc.AllReferencedDocuments
		Dim oArgs As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
		oArgs.Add("TargetDocument", oRefDoc)
		iLogicVb.Automation.RunExternalRuleWithArguments(oRefDoc, "Create 4 View Drawing Of Model", oArgs)
	Next
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 22

alessandro.brandestini
Contributor
Contributor
Hi thanks for this.
How can I save the idw to the same folder from the referenced ipt?
0 Likes
Message 11 of 22

m.rymut
Advocate
Advocate

Hi,
Thank you for your help and amount of work you put in into this.
I tried running your rule with proposed changes but i get an error:

 

mrymut_0-1652082733229.png

in english it says : undefined error.

 

I also tried running it in an assembly with the second rule you provied and i got the same error.

It starts the rule and creates an empty .idw file and then gives an error before any view is generated.

 

I have tried to find where and why the error occurs, and by just copying lines from code from up one by one i have found that the error shows on this line:

 

Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oOriginPoint, oFullScale, _
oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

 

0 Likes
Message 12 of 22

alessandro.brandestini
Contributor
Contributor
are all the documents saved?
0 Likes
Message 13 of 22

m.rymut
Advocate
Advocate

Yes, part file is saved.

I am attaching the file i was trying it on, but i get the same error for all files i try.

0 Likes
Message 14 of 22

WCrihfield
Mentor
Mentor
Accepted solution

I think I see the problem.  My editing mistake.  The variable 'oPDoc' being used as the first input variable in the AddBaseView method will most likely need to be changed to 'oTargetDoc'.  I see that I forgot to replace "oPDoc" with "oTargetDoc" in 2 locations within the code I posted in the text file.  The other location was also in a AddBaseView method, but that other line of code was left commented out.  See if that fixes the code for you.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 22

WCrihfield
Mentor
Mentor
Accepted solution

Hi @alessandro.brandestini.  In the code I posted within the text file, after the two references to the variable 'oPDoc' have been switched to 'oTargetDoc', as mentioned in my last response, you should be able to add another line of code to the end if it, as follows...just before the End Sub line.

oDDoc.SaveAs(oDrawingFullFileName, False)

That 'oDrawingFullFileName' variable was established fairly early within that code, so it already contains the full file name the code was planning on using when it saved this drawing document.   And we have already checked to see if that file already exists, with a question type prompt to the user if it did.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 16 of 22

alessandro.brandestini
Contributor
Contributor
hm sorry i don''t see through your code.
Can you write for me only the part for search ipt path and save idw in same location, please?
0 Likes
Message 17 of 22

m.rymut
Advocate
Advocate

Hi,

Yes, that was the case, code works perfectly now.

I also added the SaveAs snipplet and Close snipplet so that after saving .idw file it will close it, so that i wont end up with 100+ open .idw drawnings.

 

Thank you VERY much for your help, i will attach final code in txt files so others can use it easly.

IDW generator is for assemblies, it makes "Create 4 View Drawning From Part" rule go trough all parts, but it is the same code that you posted above.

Message 18 of 22

WCrihfield
Mentor
Mentor

Hi @alessandro.brandestini.  The code was referring to was within a text file attached to 'Message 8' of this main forum post.  But I will post just that part here in a code block for you.  Before that point, I had already established the variable 'oTargetDoc' as a Document Type variable, and made sure it was either a Part or an Assembly model document.  Then here I am using a Try...Catch block just to avoid any potential error in case the model document has not been saved to dist yet, because if it has not been saved yet, then accessing its FullFileName will result in an error, which will stop the code.  Then I made sure it had been given a value.  Then I used the ChangeExtension method to generate the expected full file name of the drawing document we want to create.  Then I used the File.Exists method to check if that file already exists. 

 

'if oTargetDoc has not been saved yet, then accessing its FullFileName will throw Error
Dim oTargetDocFFN As String = ""
Try
	oTargetDocFFN = oTargetDoc.FullFileName
Catch
	Exit Sub
End Try
If oTargetDocFFN = "" Then Exit Sub 'making sure it was filled in
Dim oDrawingFullFileName As String = System.IO.Path.ChangeExtension(oTargetDocFFN, ".idw")
If System.IO.File.Exists(oDrawingFullFileName) Then
	oOverWrite = MsgBox("A Drawing for this model already exists." & vbCrLf &
	"Do you want to over-write it?", vbYesNo + vbQuestion, "DRAWING EXISTS!")
	If oOverWrite = vbNo Then Exit Sub
End If. 

Then after that, we have variables to hold the full file name of the drawing template we want to use, and create the variable for the drawing document itself, then use the Documents.Add method to create the new drawing, which sets the value of that drawing document variable ("oDDoc").  Then the code for measuring the model, and figuring out view orientations & scale.  Then after the views have been generated, I just added the line I posted earlier:

oDDoc.SaveAs(oDrawingFullFileName, False)

Then @m.rymut added a final line right after that line, but before the 'End Sub' line:

oDDoc.Close(True)

to go ahead and close the drawing, so he didn't end up with a whole bunch of open drawings when processing a whole assembly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 19 of 22

m.rymut
Advocate
Advocate

You can go ahead and just use the code i attached above in .txt files, just comment out last line wtih oDDoc.CLose.

One thing i also changed but didn't write in the attachment above is changing where files are saved.

As i will be mostly working on assemblies and i dont want to search for all the .idw files in part files locations, so i changed 

 

 

oDDoc.SaveAs(oDrawingFullFileName, False)

 

 

to:

Dim Path As String
	Path = "C:\Users\m.rymut\Desktop\IDW\" & oTargetDoc.DisplayName & ".idw"
	oDDoc.SaveAs(Path, False)

So now all .idw files are saved in a folder on my desktop.

I am not sure about the whole "oTargetDoc.DisplayName" but it kinda works, only downside is that it containts extension of the file in its name, so it saves as "partname.ipt.idw".

 

I overcame it with this code, it works but i think there is an easier way:

Try
		
	Dim Path As String
	Path = "C:\Users\m.rymut\Desktop\IDW\" & oTargetDoc.DisplayName.Replace(".ipt", ".idw")
	oDDoc.SaveAs(Path, False)
	'oDDoc.Close(True)
	
	Catch
		
	Dim Path As String
	Path = "C:\Users\m.rymut\Desktop\IDW\" & oTargetDoc.DisplayName.Replace(".iam", ".idw")
	oDDoc.SaveAs(Path, False)
	'oDDoc.Close(True)	

	End Try
0 Likes
Message 20 of 22

alessandro.brandestini
Contributor
Contributor
You two did really good work here.
But for the moment I just need the already open idw saved on the same place then the ipt.
So I don't have to search or copy the path.
Would be nice, when you can write the code for this.
I'm sure I could find all the infos inside the existing code, but it's really hard for me to understand.
0 Likes