Section View Inventor API

Section View Inventor API

Anonymous
Not applicable
2,403 Views
3 Replies
Message 1 of 4

Section View Inventor API

Anonymous
Not applicable

Hi, everyone!

 

I’m trying to figure out how to add a detail section view working with work points as reference. The work points that I want to use are “Work Point1” and “Work Point2” in Y-BLOCK SKETCH.ipt, which I’ve attached in this post. When I run the rule “SectionView Test” in Y-BLOCK DRAWING.idw, it seems to recognize the work points in the sketch but it doesn’t create the line from one work point to another properly. Could you check out the code (in the .idw file) and tell me what’s wrong with it, please? I’ve been looking for a solution, but I’ve not found any solution to this.

 

Thank you for your consideration.

Kind regards,

Raúl

0 Likes
2,404 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

Your issue is that you are passing points to your sketch and expecting it to reference the same origin as you pulled them from, when in fact the sketch has a different origin AND SCALE.

 

If you look at the attached drawing and look at your 2 work points in comparison to the blue dot, then compare your 2 section line points in comparison to the red dot, you can see evidence of this.

 

What you have to do is base translate the workpoint points to the Origin of the view (which is the .Position call, which gives the origin location w.r.t. the drawing origin) and also for the scale (just based on what the drawing view scale is), or use some other method.

 

sample.JPG

 

(ORIGINAL CODE Attached for others to reference)

Dim oDrawingDocument As DrawingDocument = ThisServer.ActiveDocument
Dim oSheet As Sheet = oDrawingDocument.ActiveSheet
Dim oView As DrawingView = ActiveSheet.View("VIEW2").View
Dim oAssemblyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oComponentOcc As ComponentOccurrence = oAssemblyDoc.ComponentDefinition.Occurrences.Item(1)
Dim oPartDocument As PartDocument = oComponentOcc.Definition.Document
Dim oWorkPoint1 As WorkPoint = oPartDocument.ComponentDefinition.WorkPoints.Item(1)
Dim oWorkPoint2 As WorkPoint = oPartDocument.ComponentDefinition.WorkPoints.Item(2)
Dim oWorkPointProx1 As WorkPointProxy
Dim oWorkPointProx2 As WorkPointProxy
oComponentOcc.CreateGeometryProxy (oWorkPoint1, oWorkPointProx1)
oComponentOcc.CreateGeometryProxy (oWorkPoint2, oWorkPointProx2)
oView.SetIncludeStatus (oWorkPointProx1, True)
oView.SetIncludeStatus (oWorkPointProx2, True)
Dim oCenterMark1 As Centermark
Dim oCenterMark2 As Centermark
Dim oCenterMark As Centermark
    For Each oCenterMark In oSheet.Centermarks
        If oCenterMark.Attached Then
            If oCenterMark.AttachedEntity Is oWorkPointProx1 Then
                oCenterMark1 = oCenterMark
            ElseIf oCenterMark.AttachedEntity Is oWorkPointProx2 Then
                oCenterMark2 = oCenterMark
            End If
       End If
    Next
Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent)
Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent)
Dim oTG As TransientGeometry = ThisServer.TransientGeometry
Dim oPoint As Point2d = oTG.CreatePoint2d(0,0)
Dim oPointOne As Point2d
oPointOne = ThisServer.TransientGeometry.CreatePoint2d()
oPointOne.X = (oGeomIntent1.PointOnSheet.X)
oPointOne.Y = (oGeomIntent1.PointOnSheet.Y) 
Dim oPointTwo As Point2d
oPointTwo = ThisServer.TransientGeometry.CreatePoint2d()
oPointTwo.X = (oGeomIntent2.PointOnSheet.X)
oPointTwo.Y = (oGeomIntent2.PointOnSheet.Y)

Dim oDrawingSketch As DrawingSketch = oSheet.Sketches.Add
oDrawingSketch = oView.Sketches.Add
oDrawingSketch.Edit
Dim oSketchLine As SketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oPointOne, oPointTwo)
oDrawingSketch.ExitEdit
Dim oSectionView As SectionDrawingView 
oSectionView = oSheet.DrawingViews.AddSectionView(oView, oDrawingSketch, oPoint, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, 1/18, True, "L")
oSectionView.Aligned = False
ActiveSheet.View("L").SetSpacingToCorner(5, 5, SheetCorner.BottomLeft)

oCenterMark1.Visible = False
oCenterMark2.Visible = False

oDetailL = ActiveSheet.View("L").View
question = MessageBox.Show("Delete View?", "iLogic Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If question = vbYes Then
	oDetailL.Delete
End If

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

Anonymous
Not applicable

 

I understand what you say about the workpoints location, but I'm still having trouble to get the section view. I'll let you know as soon as I get it.

Thanks for your response.

 

Kind regards,

Raúl

0 Likes
Message 4 of 4

s.alaviJR58M
Explorer
Explorer

You can avoid this whole reorientation story and choose for this little detour:

- Create a centerline based on your part/assembly workplane in the context of your base view

- Create a sketch entity in the context of your sectioning sketch and use the centerline to perform "AddByProjectingEntity"

- Use the min and max points of the bounding box of this sketch entity to create a sketch line in the context of the sketch

 

Seems complicated but it is as simple as:

 

Dim oDrawAss As AssemblyDocument
Set oDrawAss = oview.ReferencedDocumentDescriptor.ReferencedDocument
Dim oSP As WorkPlane
Set oSP = oDrawAss.ComponentDefinition.WorkPlanes.Item("Center")
Dim oSL As Centerline
Set oSL = osheet.Centerlines.AddByWorkFeature(oSP, oview)
Dim oSketch As DrawingSketch
Set oSketch = oview.Sketches.Add
Dim oRefLine As SketchEntity
oSketch.Edit
Set oRefLine = oSketch.AddByProjectingEntity(oSL)
Call oSketch.SketchLines.AddByTwoPoints(oRefLine.RangeBox.MinPoint, oRefLine.RangeBox.MaxPoint)
oSketch.ExitEdit

Set opoint = ThisApplication.TransientGeometry.CreatePoint2d(osheet.Width / 2, osheet.Height * 0.2)
Dim oview2 As DrawingView
Set oview2 = osheet.DrawingViews.AddSectionView(oview, oSketch, opoint, kHiddenLineRemovedDrawingViewStyle)