SectionView Creation VB.Net

SectionView Creation VB.Net

Anonymous
Not applicable
931 Views
7 Replies
Message 1 of 8

SectionView Creation VB.Net

Anonymous
Not applicable

Hello there,

 

I want to create a SectionView via VB.NET. I'm trying this by Setting two workpoints on a subassembly and use them to create the sectionline. This subassambly is part of the whole assembly which is opened in the drawing (Setting the Workpoints on the whole assembly is not an Option)

 

I can run the Code, and a Section View is made. However, I think the coordinates I get are wrong, so I looked at them via Message Box:

 

Point 1 (906052,85.../-0,499)

Point 2 (905704,26 / -5,499)

 

Seems pretty strange. Maybe I get the Model coordinates instead of drawing coordinates?

 

    Private Sub Erstellung_Zeichnungsdatei()

        'Variables not declared here, are declared globally
        oDrawDoc = g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, g_inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))
        oSheet = oDrawDoc.ActiveSheet
        oAsmDoc = g_inventorApplication.Documents.Open(zielverzeichnis, False)
        oTG = g_inventorApplication.TransientGeometry

        Dim oAsmDoc_türrahmen As AssemblyDocument
        oAsmDoc_türrahmen = g_inventorApplication.Documents.Open(tuerrahmen_einfach, False)

        Dim oFrontView As DrawingView
        oFrontView = oSheet.DrawingViews.AddBaseView(oAsmDoc, oTG.CreatePoint2d(15, 12), 0.125, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

        Dim oWorkPoint1 As WorkPoint
        Dim oWorkPoint2 As WorkPoint
        Dim oWorkPoint1Prox As WorkPointProxy = Nothing
        Dim oWorkPoint2Prox As WorkPointProxy = Nothing
        Dim oCompocc As ComponentOccurrence
        Dim oSectionSketch As DrawingSketch
        Dim oSectionLine As SketchLine
        Dim oSectionView As SectionDrawingView


        oCompocc = oAsmDoc.ComponentDefinition.Occurrences.ItemByName("Türrahmen:1")

        oWorkPoint1 = oAsmDoc_türrahmen.ComponentDefinition.WorkPoints.Item(1)
        oWorkPoint2 = oAsmDoc_türrahmen.ComponentDefinition.WorkPoints.Item(2)

        oCompocc.CreateGeometryProxy(oWorkPoint1, oWorkPoint1Prox)
        oCompocc.CreateGeometryProxy(oWorkPoint2, oWorkPoint2Prox)

        Dim coordX_1 As Double = oWorkPoint1Prox.Point.X
        Dim coordY_1 As Double = oWorkPoint1Prox.Point.Y

        Dim coordX_2 As Double = oWorkPoint2Prox.Point.X
        Dim coordY_2 As Double = oWorkPoint2Prox.Point.Y

        Dim oPoint1 As Point2d = oTG.CreatePoint2d(coordX_1, coordY_1)
        Dim oPoint2 As Point2d = oTG.CreatePoint2d(coordX_2, coordY_2)

        MsgBox("Y_1: " & coordY_1)
        MsgBox("X_1: " & coordX_1)
        MsgBox("Y_2: " & coordY_2)
        MsgBox("X_2: " & coordX_2)

        oSectionSketch = oFrontView.Sketches.Add
        oSectionSketch.Edit()
        oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)
        oSectionSketch.ExitEdit()

        oSectionView = oSheet.DrawingViews.AddSectionView(oFrontView, oSectionSketch, oTG.CreatePoint2d(34, 10), DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, Nothing, False)

End Sub

Any help would be much appreciated.

 

 

 

0 Likes
Accepted solutions (1)
932 Views
7 Replies
Replies (7)
Message 2 of 8

smilinger
Advisor
Advisor
You should not use the workpoint coords from 3D space to draw a line in drawing, they are different world. You need to project your workpoint to the drawingview space, using something like DrawingView.ModelToDrawingViewSpace.

See this:
http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-EEDEEDB9-EEED-4A4A-A693-CFB52677C2E7
Message 3 of 8

dgreatice
Collaborator
Collaborator

Hi,

 

maybe you find clue in here.

 

https://www.youtube.com/watch?v=X2EzZDiCTZ4

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 4 of 8

Anonymous
Not applicable

Thanks for your answers!

 

I tried using the ModeltoDrawingviewSpace Method, however I'm not able to solve the Error which says it's unable to cast the objects. I think thats because the ModeltoDrawingViewSpace Needs a "Point", not a "Workpoint". Is there a way to somehow convert my workpoint to a Point? 

 

 

        oPoint1 = oFrontView.ModelToDrawingViewSpace(oWorkPoint1Prox)            
        oPoint2 = oFrontView.ModelToDrawingViewSpace(oWorkPoint2Prox)

Because this didn't work I tried using "DrawingCurves", but I get a Cast error aswell 

 

        'oDrawCurves = oFrontView.DrawingCurves(oWorkPoint1Prox) 'Cast Error
        'oDrawCurve1 = oDrawCurves(1)


        'oDrawCurves = oFrontView.DrawingCurves(oWorkPoint2Prox)
        'oDrawCurve2 = oDrawCurves(1)

        'Dim oPoint1 As Point2d = oDrawCurve1.MidPoint
        'Dim oPoint2 As Point2d = oDrawCurve2.MidPoint

---

 

Sadly the yt Video couldn't help me, in the Video the section line is created by defining two oTG Points right here

 

oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oTG.CreatPoint2d(x,y), oTG.CreatePoint2d(x,y)

But I Need it to look somehow like this:

 

oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oPoint1, oPoint2)

With oPoint1 and oPoint2 beeing the Coordinates of my Workpoints in my subassembly.

 

Do you know how I can solve the cast Errors?

Or is there a different Approach?

0 Likes
Message 5 of 8

smilinger
Advisor
Advisor
Accepted solution

I have modified the code for you, I tested it and it should work.

 

Private Sub Erstellung_Zeichnungsdatei()

        'Variables not declared here, are declared globally
        oDrawDoc = g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, g_inventorApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))
        oSheet = oDrawDoc.ActiveSheet
        oAsmDoc = g_inventorApplication.Documents.Open(zielverzeichnis, False)
        oTG = g_inventorApplication.TransientGeometry

        Dim oFrontView As DrawingView
        oFrontView = oSheet.DrawingViews.AddBaseView(oAsmDoc, oTG.CreatePoint2d(15, 12), 0.125, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

        Dim oCompocc As ComponentOccurrence
        oCompocc = oAsmDoc.ComponentDefinition.Occurrences.ItemByName("Türrahmen:1")

        Dim oWorkPoint1 As WorkPoint
        Dim oWorkPoint2 As WorkPoint
        Dim oWorkPoint1Prox As WorkPointProxy
        Dim oWorkPoint2Prox As WorkPointProxy
		
        'are you sure you want the origin point here?
	'oWorkPoint1 = oCompocc.Definition.WorkPoints.Item(1)
		
	'assuming there are 2 workpoints besides the origin point
        oWorkPoint1 = oCompocc.Definition.WorkPoints.Item(2)
        oWorkPoint2 = oCompocc.Definition.WorkPoints.Item(3)
        oCompocc.CreateGeometryProxy(oWorkPoint1, oWorkPoint1Prox)
        oCompocc.CreateGeometryProxy(oWorkPoint2, oWorkPoint2Prox)

	'get the point in the drawingview representing the point from 3D space
	Dim oPoint2d1 As Point2d = oFrontView.ModelToDrawingViewSpace(oWorkPoint1Prox.Point)
	Dim oPoint2d2 As Point2d = oFrontView.ModelToDrawingViewSpace(oWorkPoint2Prox.Point)
		
        Dim oSectionSketch As DrawingSketch
        Dim oSectionLine As SketchLine
        Dim oSectionView As SectionDrawingView

        oSectionSketch = oFrontView.Sketches.Add()
        oSectionSketch.Edit()
        oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oPoint2d1, oPoint2d2)
        oSectionSketch.ExitEdit()

        oSectionView = oSheet.DrawingViews.AddSectionView(oFrontView, oSectionSketch, oTG.CreatePoint2d(34, 10), DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, Nothing, False)

End Sub
0 Likes
Message 6 of 8

Anonymous
Not applicable

I finally found a way to convert a Workpoint to a Point, and it's way easier than I thought it would be. 

 

        Dim oPoint1 As Point
        Dim oPoint2 As Point

        oPoint1 = oWorkPoint1Prox.Point
        oPoint2 = oWorkPoint2Prox.Point

 With that the Method ModelToDrawingViewSpace works like a charm. 

 

 

I noticed one very strange Thing: 

I got the workpoints with "asmDoc.ComponentDefinition.WorkPoints.Item(<index as number>)" which resulted in wrong Sketches. After I changed it to "asmDoc.ComponentDefinition.WorkPoints.Item(<Name of Workpoint>)" it worked. Which is weird because I only have 2 Workpoints in the Assembly.

 

0 Likes
Message 7 of 8

smilinger
Advisor
Advisor
0 Likes
Message 8 of 8

Anonymous
Not applicable

Yeah as I posted my Reply I haven't seen yours yet.

 

Boy, if I had known this earlier. Thanks a lot!

0 Likes