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: 

Automate idw drawing file creation for all ipart members

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
mbgustin
4081 Views, 21 Replies

Automate idw drawing file creation for all ipart members

I'm sure this is possible and likely simple, I just don't know how to do it.  I'm looking for a way to automate the creation of an idw file for each member of my ipart.

 

I have a large project that will have me making large ipart factories with several hundred members.  I'm drawing hydraulic seals that have a range of diameters and then also have different cross sections.  We typically do not like to use tabulated drawings because it causes manufacturing errors when someone reads the table incorrectly.  I use custom property fields to place text in the drawing file based on the ipart member.  So basically the drawing file views remain the same but text/notes change with each member. 

What I'd like to do is make one drawing file that is tied to the first member adding all my views and dimensions and then have a program that changes the member and does a save as with the file name being equal to the member name.

 

Currently I make the ipart file and generate all the members.  Then I generate the first drawing and save it as membername.idw.  I then change the member associated with the main view and do a save as newmembername.idw...over and over again until I have a drawing file for each member.  Automating this would be a huge efficiency gain.

21 REPLIES 21
Message 2 of 22
Cadmanto
in reply to: mbgustin

It seems to me the best method for doing this would be through iLogic.

See the attached thread and see if it helps you.

https://forums.autodesk.com/t5/inventor-customization/ilogic-coding-to-create-automated-drawing/td-p... 

 

EE LOGO.png
Windows 10 x64 -16GB Ram
Intel i7-6700 @ 3.41ghz
nVidia GTS 250 - 1 GB
Inventor Pro 2020

 

Best Regards,
Scott McFadden
(Colossians 3:23-25)


Message 3 of 22
mbgustin
in reply to: Cadmanto

Thanks for the reply, but this isn't what I'm looking for.  I don't want to automate the drawing process.  I want to automate the generation of an idw file for every member of an ipart file using an existing idw.

Message 4 of 22
johnsonshiue
in reply to: mbgustin

Hi! I think there are mainly two ways to do it.

Option 1: Open the idw file. Create a new sheet. Copy the existing views from the old sheet to the new one. Edit the base view -> Model State -> change it to a different member.

 

Option 2:

Save the existing idw file as a different idw -> go to Manage -> Replace Model Reference -> pick a new iPart member file.

 

You need to automate one of the two workflows. Some of the annotations may become sick after you change it to a different iPart member.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 5 of 22
mbgustin
in reply to: johnsonshiue

Option 2 is the closest to what I want to do.....so how do I automate that?

 

I am currently creating the idw file with all the "stuff".  I save it.  Then I change the view to select the next member and save as a new name.  Rinse repeat until all members have an idw file.  I believe this should be simple....I just lack the knowledge to program it.

Message 6 of 22
johnsonshiue
in reply to: mbgustin

Hi!

 

I am not a developer or programmer either. I google the terms "Autodesk Inventor Replace Model Reference iLogic" and here are a few links.

 

https://forums.autodesk.com/t5/inventor-customization/modify-referenced-model-by-ilogic/m-p/3549630/...

https://forums.autodesk.com/t5/inventor-customization/ilogic-to-replace-model-reference-in-idw/td-p/...

 

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 7 of 22
mbgustin
in reply to: johnsonshiue

Thanks for trying.  I do appreciate the willingness to help.  I feel like I haven't communicated what I'm looking for very effectively.

I need a program that finds all of the members of my ipart and generates an .idw file with the same filename and also references the associated member in the a view on the idw.   Maybe this cannot be done.

Message 8 of 22
johnsonshiue
in reply to: mbgustin

Hi! I believe it is doable. I recalled I have seen the code before but I need to search for it. The links I share are for Replace Model Reference. It is also a viable workflow to do what you want to do. Essentially copy the drawing views and replace the reference with another member.

Let me look for the code.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 9 of 22
Yijiang.Cai
in reply to: mbgustin

@mbgustin , I have created a sample using iLogic rule. You could open the drawing and run the iLogic rule. The drawing file for each member file will be generated automatically.

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 10 of 22
mbgustin
in reply to: Yijiang.Cai

Awesome.  I really appreciate the efforts here.  I'm currently working on a large i-part drawing.  I will test this when completed and see how it goes.

Message 11 of 22
mbgustin
in reply to: Yijiang.Cai

I'm not finding any rules in the files.  What am I doing wrong?

Message 12 of 22
Yijiang.Cai
in reply to: mbgustin

Sorry for the confusion! The code sample is located in drawing document within VBA editor. You could access it for details. 

 

I also copy & paste the code lines here, and hope it helpful for you.

Sub CreateDrawing()
Dim oDrawingDoc As DrawingDocument
Set oDrawingDoc = ThisApplication.ActiveDocument

Dim oView As DrawingView
Set oView = oDrawingDoc.ActiveSheet.DrawingViews(1)

Dim oPartDoc As PartDocument
Set oPartDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oDef As PartComponentDefinition
Set oDef = oPartDoc.ComponentDefinition

If oDef.IsiPartMember = True Then
Dim iPartF As iPartFactory
Set iPartF = oDef.iPartMember.ParentFactory

For i = 1 To iPartF.TableRows.Count - 1

Set oPartDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim sPath As String
sPath = Replace(oPartDoc.FullFileName, iPartF.FileNameColumn(i).Value, iPartF.FileNameColumn(i + 1).Value)

Call iPartF.CreateMember(i + 1)

Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(sPath)

Call oDrawingDoc.Update2(True)

Call oDrawingDoc.SaveAs(Replace(oDrawingDoc.FullFileName, iPartF.FileNameColumn(1).Value, iPartF.FileNameColumn(i + 1).Value), True)
Next
End If

End Sub

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 13 of 22
mbgustin
in reply to: Yijiang.Cai

Thank you!

 

I wasn't looking in the VBA, that's what I was missing.  I haven't had time to work on this lately hopefully I can get to ity this week.

Message 14 of 22
mbgustin
in reply to: Yijiang.Cai

We are very close to getting this to work.  I have run the program successfully with your supplied files.  However, it does not work with mine.

 

I get a runtime 5 error.

 

Could it be because I do not increment my file names with -01, -02, etc?  My files names are based on a unique part number.

 

The member names look like this

PF0-00250-T05-N

PF0-00500-T05-N

PF1-01000-T05-N

 

The idw file will match the member name.  The member name is generated in the spreadsheet using a concatenate function.

 

 

Message 15 of 22
Yijiang.Cai
in reply to: mbgustin

@mbgustin , it is not related to the member name like "-01". I use the file name column to generate the member files and drawing files. But I create the drawing file using the first member file, and will generate the member files and drawing files from row index 1 to the max row index. It does not matter what member name or part number you use in the iPart table.

 

Please see the new sample.

 

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 16 of 22
mbgustin
in reply to: Yijiang.Cai

Success!

 

I finally figured out why it wasn't working.

 

There are a coupe of rules to make this work.  The first member name (.ipt) cannot be the same file name as the family file (.ipt) name.   After you run the program don't save the *.idw file when you close, because it is referencing the last member name in the family.  If you save it you have to open it and change the member name back to the original and save again.

 

This is a huge time saver!  Thank you!

 

Message 17 of 22
v.krempel
in reply to: mbgustin

Hello mbgunstin, I am trying the same for a Iassembly. Creating drawings for all the members with one press of a button. Do you have any reference to your code?
Message 18 of 22
A.Acheson
in reply to: v.krempel

@v.krempel 

Here is a code in the link below and the last post for creating iAssembly members to drawing. It is adapted from what you see above and it changes the parts list if present to be the member file and sets the member the rule finishes on back to the first member which eliminates that accidental save with the filename and member being different.

https://forums.autodesk.com/t5/inventor-customization/auto-updation-of-drawing-views-of-iparts-to-ac...

 

If you detail the first member up and include all notes save then run the rule. You will notice some annotations move around as the member views increase etc.  But hopefully they are only simple tweaks required. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 19 of 22
v.krempel
in reply to: mbgustin

If by any chance someone hits up this thread by google. Here is how I fixed it:

 

Generate all members of the assembly, by running this rule in the Iassembly:

 

'Shortcut for Inventor Application.
oApp = ThisApplication

'Shortcut for Document containing this rule.
oDoc = ThisDoc.Document

'Turn on Silent Operation to deactivate all pop-ups.
oApp.SilentOperation = True

'Turn on Error checking to skip to the end of the rule.
On Error GoTo jmpEndRule

'Start a transaction in the change manager to save on memory operations.
oTxn = oApp.TransactionManager.StartTransaction(oDoc, "iAssembly Generation")

'Shortcut for iAssembly Factory.
iAF = oDoc.ComponentDefinition.iAssemblyFactory

'Activate this code to generate all members in the Factory.
For Each oRow As iAssemblyTableRow In iAF.TableRows
	iAF.CreateMember(oRow)
Next

'Activate this code to generate single members or a group of members based on row numbers.
'For i = 1 To 10 'Put the same number in both places to generate that single member.
'	iAF.CreateMember(i)
'Next

'End Transaction in the change manager.
jmpEndRule : oTxn.End

'Turn Silent Operation off to return user interface back to normal.
oApp.SilentOperation = False

 

Now create a IDW file for the Iassembly master file.

Copy this drawing to match all the generated members file names.

I created a *.bat file and making the commands using excel:

 

Copy "Master drawing.idw" "./Master model/Member model.idw"

 

I open all the drawings in Inventor by drag and drop and run a rule to make *.idw reference *.iam

 

For Each doc As Document In ThisApplication.Documents.VisibleDocuments
	If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		iLogicVb.Automation.RunExternalRule(doc, "Make drw equal iam")
	End If
Next

--
Make drw equal iam:
--

docName = ThisDoc.PathAndFileName(False) & ".iam"

doc = ThisDoc.Document
Dim oFD As FileDescriptor
oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(docName)

InventorVb.DocumentUpdate()
ThisDoc.Save

 

After that rule I generate all the drawings:

 

Class ThisRule

Dim oDoc = Nothing

Sub Main()

For Each oDoc In ThisApplication.Documents.VisibleDocuments
        If oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
            oDoc.Activate()
			Publish()
			oDoc.Close()
        End If
Next oDoc

End Sub

Sub Publish()

Your publish rule

End Sub

End Class

 

Don"t ask me about the code, I just spend half a day googling and trowing it in there until I got the result I wanted.

 

Message 20 of 22
A.Acheson
in reply to: v.krempel

@v.krempel 

Did the previous iLogic code work for you? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report