Create DetailView Using iLogic/VBA, Selecting View Center by Attribute Name

Create DetailView Using iLogic/VBA, Selecting View Center by Attribute Name

insomnix
Advocate Advocate
1,520 Views
5 Replies
Message 1 of 6

Create DetailView Using iLogic/VBA, Selecting View Center by Attribute Name

insomnix
Advocate
Advocate

In the below code I am trying to dynamically create a DetailView. I started in iLogic, but moved to VBA because there are more troubleshooting options and examples in VBA. Eventually this will move back into iLogic. I started with the Add detail drawing view code sample from the knowledge base.

 

From there I tried to identify the hole to place the detail view on. For this I used the attribute manager to find the hole by name (thank you Attribute Helper Addin). While everything works without error, the detail view is placed way off to the side and not on the hole I am referencing. After some reading I think the problem is that I need to pass the center point through a GeometryProxy. There are plenty of examples of how to do that in an assembly, but I could find nothing on how to do that from an IDW. I'm not even certain that is the solution to this problem. 

 

Though not as important to solve, there is also a line of code near the beginning that requires the user to select the parent view. I would like to select the view automatically by name. I could build a loop to find it, but I was hopping that it could be done with a single line of code similar to the line of iLogic code underneath that is commented out.

 

Sub CreateView()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Select a drawing view.
    Dim oDrawingView As DrawingView
    Set oDrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select view") '<--- need to select view by view name.
    'Set oDrawingView = ActiveSheet.View("BACK").View <--- iLogic code to get correct parent view

    Dim oPartDoc As PartDocument
    Set oPartDoc = oDrawingView.ReferencedFile.ReferencedDocument
    
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    Set oSheet = oDrawingView.Parent

    ' Set a reference to the center of the base view.
    Dim oPoint As Point2d
    Set oPoint = oDrawingView.center

    ' Translate point by a distance equal to the width of the view
    ' This will be the placement point of the detail view.
    oPoint.X = oPoint.X + oDrawingView.Width
    
    Dim aoEdge1 As Face
    Set oObjs = oPartDoc.AttributeManager.FindObjects("HINGE_HOLE_TOP", "DIM", "1")
    Set aoEdge1 = oObjs.Item(1)
    
    Dim centerPoint As Point
    Dim circ As Inventor.Circle
    Set circ = aoEdge1.Edges.Item(1).Geometry
    Set centerPoint = circ.center

    ' Ready code for creating of reference points
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    If Not centerPoint Is Nothing Then
        ' Use the range of the arc in sheet space to calculate the detail view box.
        Dim oCenterPoint As Point2d
        Set oCenterPoint = oTG.CreatePoint2d(centerPoint.X, centerPoint.Y)

        ' Create the detail view.
        Dim oDetailView As DetailDrawingView
        Set oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, kFromBaseDrawingViewStyle, True, oCenterPoint, 0.5, , 0.5, True, "A")
    Else
        MsgBox "No center point was found in the selected drawing view."
    End If
End Sub

Extra info:

I try to set up idw's in a way that views do not not need to be generated through code. Usually I handle this by strategically grouping like parts and handling variations through other ways. The reason for this is to create a library that most anyone with a modicum of experience can maintain. Now I am to the point where things are starting to get more complicated. Hopefully someone can help me out here.

0 Likes
Accepted solutions (1)
1,521 Views
5 Replies
Replies (5)
Message 2 of 6

insomnix
Advocate
Advocate
Accepted solution

Found the solution. Working on something else led to the realization that there was a gap between finding the face through the attribute manager and selecting the center point of the hole on the view. Passing the face to the drawing view drawing curve allowed me to find the center point of the hole on the view. The change to the code is shown below. 

    Dim aoEdge As Face
    Set oObjs = oPartDoc.AttributeManager.FindObjects("HINGE_HOLE_TOP", "DIM", "1")
    Set aoEdge = oObjs.Item(1)

    Dim aoDrawCurves As DrawingCurve
    Set oDrawViewCurves = oDrawingView.DrawingCurves(aoEdge.Edges(1))
    Set aoDrawCurves = oDrawViewCurves.Item(1)
    
    Dim centerPoint As Point2d
    Set centerPoint = aoDrawCurves.centerPoint

More work to do, but the problem titled in this thread is resolved.

0 Likes
Message 3 of 6

sohaib.as01
Advocate
Advocate

Hello Mate,

I was wondering if you were able to find out how to set parent view for Detail view using single line of code instead selecting it?? As I am stuck in the same problem and cant find any good solution for it.

And also can you explain a bit as to how you are telling the code to place the centre of the detail view circle on and also how big the circle needs to be? and in turn the scale of the resulting detail view?

Any help will be very much appreciated 🙂

Thank you.

Sohaib.

0 Likes
Message 4 of 6

insomnix
Advocate
Advocate

It is actually commented out in the code. This line will select the view to add the detail view.

 

  'Set oDrawingView = ActiveSheet.View("BACK").View <--- iLogic code to get correct parent view

 

Everything you need to set the drawing view is done on the set oDetailView line. 

 

Set oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, kFromBaseDrawingViewStyle, True, oCenterPoint, 0.5, , 0.5, True, "A")

 I tried to find the API knowledge on the website, but the page does not appear to exist anymore. Maybe one of the autodesk moderators can find the updated page for https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-API/files/Dr...

What you could do, is with Inventor open, go to the help drop down and find the API help topics and sear for AddDetailView. I use this help a lot and it will break down the values that can be placed in this function.

0 Likes
Message 5 of 6

sohaib.as01
Advocate
Advocate

Hey thanks for the reply and thanks for pointing out the lines.

But i guess wasnt clear in what I asked.

I want to understand this

0 Likes
Message 6 of 6

sohaib.as01
Advocate
Advocate

hey, thanks for the reply and thank you fro pointing out what I asked.

Actually I guess I wasnt being clear in what I asked, so let me ask n detail

I want to know whats happening in these line of code:

I know in this line you are using attribute manager to get the dimensions from, but I dont really understand the detail of this line

Dim aoEdge1 As Face
    Set oObjs = oPartDoc.AttributeManager.FindObjects("HINGE_HOLE_TOP", "DIM", "1")
    Set aoEdge1 = oObjs.Item(1)

 And then i really dont understand whats happening in these lines; what is the variable DrawingCurves used for? What curve is it detecting in the view? What does it refers to?

 Dim aoDrawCurves As DrawingCurve
    Set oDrawViewCurves = oDrawingView.DrawingCurves(aoEdge.Edges(1))
    Set aoDrawCurves = oDrawViewCurves.Item(1)
    
    Dim centerPoint As Point2d
    Set centerPoint = aoDrawCurves.centerPoint
0 Likes