- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
Solved! Go to Solution.