Inventor Customization

Posts: 3
Registered: ‎01-14-2013
Message 1 of 3 (336 Views)
Accepted Solution

use the loaded IPT on IDW Through VBA

336 Views, 2 Replies
01-16-2013 04:03 AM




I'm working on a program where i'd like to take an assembly, open a part of it, and through a macro automaticaly export that part to an IDW. I already have a program where i take the part and export it to the idw, but on my program i must identify the path of the part. Does anybody know how to use the part that it's already loaded on inventor? When you create a new idw, if you've an openned part it automaticaly loads on the base view. I'd like to do the same.


Best Regards


ADN Support Specialist
Posts: 467
Registered: ‎06-02-2009
Message 2 of 3 (316 Views)

Re: use the loaded IPT on IDW Through VBA

01-21-2013 02:38 AM in reply to:

Hi Nivaldo,


There are several ways to access a loaded document, it depends from where you want to retrieve it. The Application.ActiveDocument will return the document that is currently visible in the UI. If you work with an assembly, you can access the document that a specific occurrence is referencing using "AssemblyComponentDefinition.Occurrences(idx).Definition.Document".


Without a bit more context, it is hard to give you a more detailed answer.




Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Posts: 3
Registered: ‎01-14-2013
Message 3 of 3 (309 Views)

Re: use the loaded IPT on IDW Through VBA

01-21-2013 03:13 AM in reply to: philippe.leefsma

Thanks Philippe!


It helped a lot.


I've found another way to do the same thing i was trying to do, but without use the document which is already oppened.

Through a saving comand i created a a temporary file of the part in a folder and used that  file with a standard name and path to create my IDW. It works well too, but running that it takes a little bit more of time until it creates the temp. part.



That's the program i created:



'Salvar a peça em uma pasta temporária para importação no IDW / Save the part as a Temporary Part in a especific folder


Dim invApp As Inventor.Application
Set invApp = ThisApplication
'invApp.SilentOperation = True

Dim iptDoc As Inventor.PartDocument
Set iptDoc = invApp.ActiveDocument

Dim iptFile As String
LaserDir = "c:\temp\Macro\"
iptFile = LaserDir + "Temp.ipt"

With invApp.CommandManager
Call .PostPrivateEvent(kFileNameEvent, iptFile)
Call .StartCommand(kFileSaveCopyAsCommand)
End With

Set iptDoc = Nothing
'invApp.SilentOperation = False
Set invApp = Nothing




' Criar um novo documento baseando-se no Template padrão / Create a new document based on the standard template

    Dim oDrawnDoc As DrawingDocument
    Set oDrawnDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, _
'************Plotar a peça salva em um arquivo do IDW / Use the temporary part on the IDW

  ' Set a reference to the drawing document.
  ' This assumes a drawing document is active.
  Dim oDrawDoc As DrawingDocument
  Set oDrawDoc = ThisApplication.ActiveDocument

  'Set a reference to the active sheet.
  Dim oSheet As Sheet
  Set oSheet = oDrawDoc.ActiveSheet

  ' Create a new NameValueMap object
  Dim oBaseViewOptions As NameValueMap
  Set oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

  ' Open the model document (corresponding to the "MyLODRep" representation).
  Dim Abc As String
  Abc = ThisApplication.FileManager.GetFullDocumentName("C:\Temp\Macro\Temp.ipt")

  Dim oModel As Document
  Set oModel = ThisApplication.Documents.Open(Abc, False)

  ' Create the placement point object.
  Dim oPoint As Point2D
  Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 25)
   ' Create a base view.
  Dim oBaseView As DrawingView
  Set oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 0.5, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions)






You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community

Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor