Open model from drawing [VBA]

Open model from drawing [VBA]

Anonymous
Not applicable
3,761 Views
8 Replies
Message 1 of 9

Open model from drawing [VBA]

Anonymous
Not applicable

Hi All,

 

Simply I need to open the model (ipt/iam)from the drawing with VBA

 

Public Sub Test_Click()

Dim oDocument As Inventor.DrawingDocument
    Set oDocument = ThisApplication.ActiveDocument

    ThisApplication.Documents.Open(ThisDrawing.ModelDocument.FullFileName)
     
End Sub

  

Could any one help my with the simple soution ? The code abowe dosent work 

 

 

 

0 Likes
Accepted solutions (1)
3,762 Views
8 Replies
Replies (8)
Message 2 of 9

MechMachineMan
Advisor
Advisor
Dim oDwgDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oModelDoc As Document

For Each oSheet In oDwgDoc.Sheets
oSheet.Activate
oDrawingView = oSheet.DrawingViews.Item(1)
oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
ThisApplication.Documents.Open(oModelDoc.FullDocumentName, True) ' False for invisbly opened


Next

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi 

Thank you for the help...but i am getting the error:

 

2015-04-23 19_57_48-Microsoft Visual Basic for Applications - 09042015.ivb [running] - [ExportFromID.jpg

0 Likes
Message 4 of 9

MechMachineMan
Advisor
Advisor
Hmmm. Not at clue. It works perfectly for me just like that inside of inventor.

It could be because it is written in vb.net instead of vba, so it might be missing Call in front of the last line.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 9

Anonymous
Not applicable

Yes, it works as Ilogic rule (VB.Net) but I need this for my macro so i need this in VBA.....

0 Likes
Message 6 of 9

MechMachineMan
Advisor
Advisor
And that's where you get to have fun with it 🙂 I'm clueless as to how vba
would be written different

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 7 of 9

Anonymous
Not applicable
Accepted solution

Ok i didi it 🙂

 

Dim oDwgDoc As DrawingDocument
    Set oDwgDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oModelDoc As Document

For Each oSheet In oDwgDoc.Sheets
oSheet.Activate
Set oDrawingView = oSheet.DrawingViews.Item(1)
Set oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Call ThisApplication.Documents.Open(oModelDoc.FullDocumentName, True) ' False for invisbly opened
Next

 And it works 🙂

Thanks for help

Message 8 of 9

MechMachineMan
Advisor
Advisor
Pretty Simple, so it was just adding "Set" And "Call" to convert it?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 9

Anonymous
Not applicable

Yes 🙂

0 Likes