Creating 4 views

Creating 4 views

tomislav.peran
Advocate Advocate
1,367 Views
14 Replies
Message 1 of 15

Creating 4 views

tomislav.peran
Advocate
Advocate

Hello,

 

I have tried to add views to my sheet but I can not seem to add projected views with the current code. 

 

Should I just use "AddBaseView" everywhere instead of "AddProjectedView" because something is not working

 

with "AddProjectedView" option. Also it does not contain view orientation in itself so I am curious how program

 

knows how to choose the right side of the projected view. 

 

This is idea:

 

tomislavperan_0-1652088130923.png

 

And the code:

 

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument 

Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)

Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 10)

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(30, 10)

Dim oPoint4 As Point2d  = ThisApplication.TransientGeometry.CreatePoint2d(30,20)

Dim oPath As String = System.IO.Path.GetDirectoryName(oDrawingDoc.FullFileName)

Dim oAssyFullFileName As String = System.IO.Path.Combine(oPath, "iMachineIsland_top_assy.iam")

Dim oAssyDoc As AssemblyDocument = ThisApplication.Documents.Open(oAssyFullFileName, False) 

Dim oBaseView As DrawingView

oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 1, kTopViewOrientation, kHiddenLineDrawingViewStyle)

Dim oView2 As DrawingView

oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2,kFromBaseDrawingViewStyle) 

Dim oView3 As DrawingView

oView3 = oSheet.DrawingViews.AddProjectedView(oView2, oPoint3, kFromBaseDrawingViewStyle) 

Dim oIsoView As DrawingView

Dim IsoView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)

oAssyDoc.Close(True)

In case anyone knows what is wrong here with creating View 2 and View 3 please let me know. 

 

Tom

Accepted solutions (1)
1,368 Views
14 Replies
Replies (14)
Message 2 of 15

SevInventor
Advocate
Advocate

Hello Tomislav,

instead of

oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2,kFromBaseDrawingViewStyle)

try

 

 

oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)

that works in one of my rules

Message 3 of 15

tomislav.peran
Advocate
Advocate

Hi SevInventor,

 

I still get the same errors:

 

De parameter is onjuist. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Error on line 26 in rule: Add view, in document: iMachineIsland_top_assy.idw

Klasse is niet geregistreerd

 

But thank you for your reply!

 

Tom

0 Likes
Message 4 of 15

SevInventor
Advocate
Advocate

try catch works here. I still don't know the reason for the error

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument 

Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)

Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 10)

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(30, 10)

Dim oPoint4 As Point2d  = ThisApplication.TransientGeometry.CreatePoint2d(30,20)

Dim oPath As String = System.IO.Path.GetDirectoryName(oDrawingDoc.FullFileName)

Dim oAssyFullFileName As String = System.IO.Path.Combine(oPath, "iMachineIsland_top_assy.iam")

Dim oAssyDoc As AssemblyDocument = ThisApplication.Documents.Open(oAssyFullFileName, False) 

Dim oBaseView As DrawingView

oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 1, kTopViewOrientation, kHiddenLineDrawingViewStyle)

Dim oView2 As DrawingView
	Try
	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2,DrawingViewStyleEnum.kFromBaseDrawingViewStyle) 
	Catch 
	end try
Dim oView3 As DrawingView
	Try

	oView3 = oSheet.DrawingViews.AddProjectedView(oView2, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) 
	Catch 
	End Try

Dim oIsoView As DrawingView

Dim IsoView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)

oAssyDoc.Close(True)

 

0 Likes
Message 5 of 15

tomislav.peran
Advocate
Advocate

I get no error indeed but also no views (except for the base and iso view where I use AddBaseView option). 

 

If I figure it out where sits the mistake I will post it here.

 

Tom

0 Likes
Message 6 of 15

SevInventor
Advocate
Advocate

At this point it is not possible to place a paralell viev:

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(30, 10)

but for example here:

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 30)

 

 

0 Likes
Message 7 of 15

tomislav.peran
Advocate
Advocate

I have tried that as well but with no succes...

0 Likes
Message 8 of 15

SevInventor
Advocate
Advocate

this works for me:

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument 

Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)

Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 10)

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 30)

Dim oPoint4 As Point2d  = ThisApplication.TransientGeometry.CreatePoint2d(30,20)

Dim oPath As String = System.IO.Path.GetDirectoryName(oDrawingDoc.FullFileName)

Dim oAssyFullFileName As String = System.IO.Path.Combine(oPath, "iMachineIsland_top_assy.iam")

Dim oAssyDoc As AssemblyDocument = ThisApplication.Documents.Open(oAssyFullFileName, False) 

Dim oBaseView As DrawingView

oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 1, kTopViewOrientation, kHiddenLineDrawingViewStyle)

Dim oView2 As DrawingView
'	Try
	oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) 
'	Catch 
'	end try
Dim oView3 As DrawingView
'	Try

	oView3 = oSheet.DrawingViews.AddProjectedView(oView2, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) 
'	Catch 
'	End Try

Dim oIsoView As DrawingView

Dim IsoView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)

oAssyDoc.Close(True)
0 Likes
Message 9 of 15

tomislav.peran
Advocate
Advocate

Yes, it looks good. I have checked Inventor Help multiple times and the code for AddProjectView should look like you wrote it.

 

I will try again later. Maybe it will work then...

 

 

0 Likes
Message 10 of 15

SevInventor
Advocate
Advocate

Here is a problem:

Dim oIsoView As DrawingView

Dim IsoView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)

should be 

Dim oIsoView As DrawingView

oIsoView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 1, kIsoTopLeftViewOrientation, kHiddenLineDrawingViewStyle)

a

0 Likes
Message 11 of 15

tomislav.peran
Advocate
Advocate

Hi Sev,

 

Yes, that is wrong but I corrected it already. Issue is in adding Projected views only. Those just can not be generated.

 

Maybe something is wrong with my files. Because code seems oke. I will try this code with other drawings to check if

 

it works.

 

But thanks a lot for helping out!

 

Tom

0 Likes
Message 12 of 15

WCrihfield
Mentor
Mentor

Hi @tomislav.peran.  Just dropping a link here to another similar post I recently worked on that you might benefit from.  The code in that other post was also creating drawings with 4 drawing views of part models, and includes code for figuring out scale and orientation of the models before placing the views.  Just in case that might help you out with your project.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 15

JelteDeJong
Mentor
Mentor
Accepted solution

I did have a look at it. I did get an exception as well on the code. but I noticed that you are placing the views very close together. My theory is that they are too close. (also manually you are not able to put a projected view directly on top of a base view.) Try this code that I altered a bit.

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)

Dim oPath As String = System.IO.Path.GetDirectoryName(oDrawingDoc.FullFileName)
Dim oAssyFullFileName As String = System.IO.Path.Combine(oPath, "iMachineIsland_top_assy.iam")

Dim oAssyDoc As AssemblyDocument = ThisApplication.Documents.Open(oAssyFullFileName, False)

Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)
Dim oBaseView As DrawingView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 0.1, ViewOrientationTypeEnum.kTopViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)


Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oPoint1.X, oPoint1.Y - oBaseView.Height)
Dim oView2 As DrawingView = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)

Dim oPoint3 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oPoint2.X + oView2.Width, oPoint2.Y)
Dim oView3 As DrawingView = oSheet.DrawingViews.AddProjectedView(oView2, oPoint3, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)


Dim oPoint4 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oPoint3.X, oPoint3.Y + oView3.Height)
Dim oIsoView As DrawingView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint4, 0.1, ViewOrientationTypeEnum.kIsoTopLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

oAssyDoc.Close(True)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 14 of 15

tomislav.peran
Advocate
Advocate

Hi WCrihfield,

 

Thank you very much for your link! Looking forward reading it 🙂

 

Tom

0 Likes
Message 15 of 15

tomislav.peran
Advocate
Advocate

Hi Jelte,

 

It looks like your theory is correct! 

 

In the original code ISO view was sucesfully created on top of the base view. But it has been seen by Inventor as an other base view not as projected view. It is logical to think that in that case distance does not matter. 

 

Thank you very much for helping, veel bedankt 🙂

 

Tom

 

0 Likes