Inventor Customization

Inventor Customization

Reply
Member
nj.net
Posts: 3
Registered: ‎01-14-2013
Message 1 of 3 (395 Views)
Accepted Solution

use the loaded IPT on IDW Through VBA

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

 

Hi!

 

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

Nivaldo.

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.

 

Regards,

Philippe.

ADN Support Specialist
philippe.leefsma
Posts: 676
Registered: ‎06-02-2009
Message 2 of 3 (375 Views)

Re: use the loaded IPT on IDW Through VBA

01-21-2013 02:38 AM in reply to: nj.net

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.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Member
nj.net
Posts: 3
Registered: ‎01-14-2013
Message 3 of 3 (368 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, _
                ThisApplication.FileManager.GetTemplateFile(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)

 

 

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.