Place drawing view using iLogic

Place drawing view using iLogic

S7RM7RPR
Advocate Advocate
2,467 Views
14 Replies
Message 1 of 15

Place drawing view using iLogic

S7RM7RPR
Advocate
Advocate

Ok so I've been trying to take the info from this post and to modify it to suit my purposes. Being that I only want one drawing view. But I'm getting an error on the last line and I'm not sure what I'm going wrong.. Also, not sheet metal, not sure what that changes...

 

http://forums.autodesk.com/t5/inventor-customization/ilogic-how-to-place-flat-pattern-on-the-drawing...

 

 

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Dim oPartDoc As Document
Dim oSheet As sheet

Dim oDoc1 As String = ThisDoc.FileName(False)
SpiderID = Right(oDoc1,(Len(oDoc1)-1)) ' Templates are named differently for different parts. In this case value is "1"

ViewScale = 1
oSheet = ThisDoc.Document.Sheets.Item(1)


Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

oBaseViewOptions.Add("SPIDER" & SpiderID & ".ipt", False)

oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(3, 10) ' front view

oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, ViewScale, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "View1")
0 Likes
2,468 Views
14 Replies
Replies (14)
Message 2 of 15

MechMachineMan
Advisor
Advisor

You call oPartDoc in the last line, but never defined what it is. (You have oDoc1 instead)


--------------------------------------
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 15

S7RM7RPR
Advocate
Advocate

Does that mean you know how to do it because that answer is a little vague on how to fix it....

0 Likes
Message 4 of 15

MechMachineMan
Advisor
Advisor

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Dim oPartDoc As Document
Dim oSheet As sheet

Dim oDoc1 As String = ThisDoc.FileName(False)
SpiderID = Right(oDoc1,(Len(oDoc1)-1)) ' Templates are named differently for different parts. In this case value is "1"

ViewScale = 1
oSheet = ThisDoc.Document.Sheets.Item(1)


Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

oBaseViewOptions.Add("SPIDER" & SpiderID & ".ipt", False)

oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(3, 10) ' front view
oSheet.DrawingViews.AddBaseView(oDoc1, oPoint1, ViewScale, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "View1")

'You called oPartDoc here, but didnt define it anywhere. use oDoc1 instead, or a different DEFINED variable 'oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, ViewScale, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "View1")

 

This synatx may be wrong, so you may need to go into the Programming Help through inventor and find what the appropriate syntax is for:

.AddBaseView

 

This will likely be the wrong format for your first parameter in .AddBaseView. I am not sure as I am not going to do all of the work for you.

Dim oDoc1 As String = ThisDoc.FileName(False)

--------------------------------------
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 15

S7RM7RPR
Advocate
Advocate

 

The syntax is correct as far as I can tell. I've simplified the code as best as I can and assuming that I've done it correctly, it's still not working. Also, as a side note I am not a programmer and this particular chunk is an entirely new function to me. I'm learning on the fly with all this so I really appreciate any help you can give me.

 

Based on the error below I'm doing something wrong with "oPartDoc" but I don't understand what

 

 

"Unable to cast object of type 'System.String' to type 'Inventor.Document'."

 

 

SpiderID = Right(ThisDoc.FileName(False),(Len(ThisDoc.FileName(False))-1))

oPartDoc = ("path\SPIDER1.ipt")

oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(9, 10) ' front view

oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc, oPoint1, 0.5, kFrontViewOrientation, kHiddenLineDrawingViewStyle, "View1")
0 Likes
Message 6 of 15

MechMachineMan
Advisor
Advisor

 

"Unable to cast object of type 'System.String' to type 'Inventor.Document'."

 


That right there says your syntax is wrong. In plain english, it's saying "You are trying to make a string go where a document belongs.

 

Looking at the rest of the code, (and if you actually checked the syntax through the programming help which is an ESSENTIAL tool for doing anything more than the absolute basics of iLogic), you would see:

 

DrawingViews.AddBaseView Method
Parent Object: DrawingViews

Description 
Method that creates a new base . The newly created DrawingView is returned.

Syntax 
DrawingViews.AddBaseView( Model As Document, Position As Point2d, Scale As Double, ViewOrientation As ViewOrientationTypeEnum, ViewStyle As DrawingViewStyleEnum, [ModelViewName] As String, [ArbitraryCamera] As Variant, [AdditionalOptions] As Variant ) As DrawingView

 Which says that the First Parameter for .AddBaseView is a document.

 

oPartDoc as you have it is a string (you can tell because it has quotation marks in it).

 

You will need to grab the Model Document itself and then pass it to add base view.

 

 

Ie;

 

Dim oPartDoc As Document

'This ensures that what you give oPartDoc is a Document Type.

 

oPartDoc = ThisApplication.ActiveDocument

'This will return the active document, which might not necessarily be what you want but it is a good example


--------------------------------------
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 7 of 15

S7RM7RPR
Advocate
Advocate
I'm confused, isn't oPartDoc the part that I want a view of? The way I have it set up is I'm trying to get the views of parts in an assembly. I need to set up 72 different templates which is why I'm trying to figure out this code. If I don't have to manually insert each view it's going to save me a lot of work

Also just to be clear, I'm using this code on the idw right?
0 Likes
Message 8 of 15

MechMachineMan
Advisor
Advisor

This also looks terribly wrong to me based upon the syntax in the Programming help.

 

If you are just trying to rename the view, you might want to look into simpler methods under the .DrawingView object.

 

Dim oBaseViewOptions As NameValueMap
oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap

oBaseViewOptions.Add("SPIDER" & SpiderID & ".ipt", False)

--------------------------------------
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 15

MechMachineMan
Advisor
Advisor
Yes, oPartDoc is supposed to be the part document.

You could get this functionality out of either an .idw or a .iam. It just depends on how the rest of your code is set up.

--------------------------------------
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 10 of 15

S7RM7RPR
Advocate
Advocate

*sigh* I needed the code in the individual parts. I'll go smack my head against the wall now.

 

New problem with that however, is that it creates a new idw instead of editing the one that I want to add the view to...

0 Likes
Message 11 of 15

MechMachineMan
Advisor
Advisor

If nothing else, you may want to look into using a Sheet Format with a view in it.

 

That way, you simply have to select to use the sheet format, and then if it contained a view, it will ask you for a file to put in it's place.

 

It will be useful for if it is all in the same .idw, but not so much if it isn't.


--------------------------------------
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 12 of 15

S7RM7RPR
Advocate
Advocate
I'm sorry I'm getting rather lost here. I put the code into my parts and it works there but it creates a new idw.

What I am trying to do is this.

I have a large number of parts.

Each part needs it's own drawing.

I can't have it set up as multiple sheets because the parts used will change all the time.

I have idw files set up for the different parts, but now I need to put a view of each part onto it's idw and save that idw. The actual format and size of the view isn't important because I still need to go through and do more editing.

Does that make sense or am I just barking up the wrong tree and should just do it manually
0 Likes
Message 13 of 15

MechMachineMan
Advisor
Advisor
I guess a lot of it depends how you were going to match your parts to your
.idws if your idws are already created.

I have made myself a code that goes through all of the parts in an
assembly, makes an idw, puts a view in it, and saves it using a formulaic
name. So it is possible if you know what you are doing.

--------------------------------------
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 14 of 15

S7RM7RPR
Advocate
Advocate
Seeing as I am totally making this up as I go it seems like I'm better off just doing it manually then. Apparently my project is getting too complicated for simple solutions >.<

Thank you very much for your help
0 Likes
Message 15 of 15

MechMachineMan
Advisor
Advisor

You could also try messing around with something like this untested code to use in your main assembly:

 

 

 

Dim oDoc As Document = ThisApplication.ActiveDocument

 

For j=0 to oDoc.ReferencedDocuments.Count

 

         oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject,"C:\Template File.idw", False)

 

         oDwgName = "C:\String here.idw"

 

       

         

         oModel = oDoc.ReferencedDocuments.Item(j)

          

         oFormat = oDrawDoc.SheetFormats.Item(3) ' Change this to whatever u want to use

         oDrawDoc.Activate

         oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel,"xxx",,,)
         oDrawingDoc.Sheets.Item(1).Delete

         oDrawDoc.SaveAs(oDwgName, True)

         oDrawDoc.Close

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