Help creating detail View using iLogic, placing the view rectangle specifically

Help creating detail View using iLogic, placing the view rectangle specifically

sohaib.as01
Advocate Advocate
2,364 Views
10 Replies
Message 1 of 11

Help creating detail View using iLogic, placing the view rectangle specifically

sohaib.as01
Advocate
Advocate

Hello everyone, hope you all are having a great day.

So, I am automating my drawings and stuck at a problem of creating drawing views. I found the code from API help about creating detail view, which is:

 ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    	oDrawDoc = ThisApplication.ActiveDocument 
        
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    	oSheet = oDrawDoc.ActiveSheet
		
		 ' Select a drawing view.
    Dim oDrawingView As DrawingView = ActiveSheet.View("FRONT").View
	
    ' Set a reference to the center of the base view.
    Dim oPoint As Point2d
    	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
	'oPoint.Y = oPoint.Y - oDrawingView.Height
    
    ' Arbitrarily find an arc within the selected drawing view.
    ' The detail view will include this arc.
    Dim oCurve As DrawingCurve
    Dim oArcCurve As DrawingCurve
    For Each oCurve In oDrawingView.DrawingCurves
        If oCurve.CurveType = kCircularArcCurve Then
             oArcCurve = oCurve
            Exit For
        End If
    Next
    
    If Not oArcCurve Is Nothing Then
        ' Use the range of the arc in sheet space to calculate the detail view box.
        Dim oCornerOne As Point2d
        	oCornerOne = oArcCurve.Evaluator2D.RangeBox.MinPoint
        oCornerOne.X = oCornerOne.X- ActiveSheet.View("FRONT").Width * 0.1
        oCornerOne.Y = oCornerOne.Y - ActiveSheet.View("FRONT").Height * 0.1
        
        Dim oCornerTwo As Point2d
        	oCornerTwo = oArcCurve.Evaluator2D.RangeBox.MaxPoint
        oCornerTwo.X = oCornerTwo.X + 0.1
        oCornerTwo.Y = oCornerTwo.Y + 0.1
        
        ' Create the detail view with a rectangular box.
        Dim oDetailView As DetailDrawingView
        	oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
        kFromBaseDrawingViewStyle, False, oCornerOne, oCornerTwo, , 2, True , "F")
    Else
        MessageBox.Show("No arc was found in the selected drawing view.")
    End If

I understood all of the code, but I am having trouble understanding this block of code, which is essentially defining the fence for the detail view and hence I am unable to place the fence where i want to.

' Arbitrarily find an arc within the selected drawing view.

' The detail view will include this arc.

Dim oCurve As DrawingCurve

Dim oArcCurve As DrawingCurve

For Each oCurve In oDrawingView.DrawingCurves

If oCurve.CurveType = kCircularArcCurve

Then

oArcCurve = oCurve

Exit For

End If

Why is it finding an arc "arbitrarily"? What is this arc anyways and whats the point of finding it?

I will be very very greatful to you for any kind of help, I have been finding the answer for two days now but couldnt find any help so thought of posting it.

Thank You

I am using Inventor 2019

0 Likes
Accepted solutions (1)
2,365 Views
10 Replies
Replies (10)
Message 2 of 11

JhoelForshav
Mentor
Mentor

Hi @sohaib.as01 

The code example you've found is to create a detail view of the first arc found in the drawing view. That's what the arc is. The code finds an arc, gets its rangebox and expands it slightly. That box is what the detail view will show. I hope this makes sense...

I rewrote the code a bit because I  didn't get a very nice box when I tried the code you posted here:

 

 ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    	oDrawDoc = ThisApplication.ActiveDocument 
        
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    	oSheet = oDrawDoc.ActiveSheet
		
		 ' Select a drawing view.
    Dim oDrawingView As DrawingView = ActiveSheet.View("FRONT").View
	
    ' Set a reference to the center of the base view.
    Dim oPoint As Point2d
    	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
	'oPoint.Y = oPoint.Y - oDrawingView.Height
    
    ' Arbitrarily find an arc within the selected drawing view.
    ' The detail view will include this arc.
    Dim oCurve As DrawingCurve
    Dim oArcCurve As DrawingCurve
    For Each oCurve In oDrawingView.DrawingCurves
        If oCurve.CurveType = kCircularArcCurve Then
             oArcCurve = oCurve
            Exit For
        End If
    Next
    
    If Not oArcCurve Is Nothing Then
		Dim oBox As Box2d = oArcCurve.Evaluator2D.RangeBox
		Dim oHeight As Double = oBox.MaxPoint.Y - oBox.MinPoint.Y
		Dim oWidth As Double = oBox.MaxPoint.X - oBox.MinPoint.X
        ' Use the range of the arc in sheet space to calculate the detail view box.
        Dim oCornerOne As Point2d = oBox.MinPoint
        oCornerOne.X = oCornerOne.X - oWidth * 0.1
        oCornerOne.Y = oCornerOne.Y - oHeight * 0.1
        
        Dim oCornerTwo As Point2d = oBox.MaxPoint
        oCornerTwo.X = oCornerTwo.X + oWidth * 0.1
        oCornerTwo.Y = oCornerTwo.Y + oHeight * 0.1
        
       Dim oScale As Double = oDrawingView.Scale * 2
        Dim oDetailView As DetailDrawingView
        	oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
        kFromBaseDrawingViewStyle, False, oCornerOne, oCornerTwo, , oScale, True , "F")
    Else
        MessageBox.Show("No arc was found in the selected drawing view.")
    End If
0 Likes
Message 3 of 11

sohaib.as01
Advocate
Advocate

Thank you for the reply @JhoelForshav

I am really sorry but I still didn't get it, this arc that it tries to find, does it comes from the part geometery or does it have to sketched on the drawing view prior to the code? 

I want the detail View to be created at four different corners of my drawing view, so I want to be able to control where the detail View fence gets placed, and apparently from the code i understand that it is just arbitrarily selecting a curve to place view fence. I am really struggling with it but it's getting on my nerves now and can't figure out that simple thing 😞

0 Likes
Message 4 of 11

JhoelForshav
Mentor
Mentor

@sohaib.as01 

The curve it selects is the arc. It does select the firt arc (drawing curve that is of type CircularArc in the drawing view) and creates the fence around it. The fence is defined by two corner points. These to corner points are taken from the arcs rangebox (an imaginary box containing the drawing curve). So in your case, what you want to do is to skip all this arc business and figure out how to define these points so that they make a fence around the section of your view that you want your detail view to represent.

0 Likes
Message 5 of 11

sohaib.as01
Advocate
Advocate

Alright @JhoelForshav, so you mean I don't even have to bother with the block of code which is looking for the circular arc in my drawing view and can just figure another way to draw that fence where I want? 

0 Likes
Message 6 of 11

JhoelForshav
Mentor
Mentor

@sohaib.as01 

Exactly... All you need is two points (Point2d) representing the corner points of your fence.

Message 7 of 11

sohaib.as01
Advocate
Advocate

Alright, so I went by your logic, which made sense and edited the code accordingly. But now it is giving me error;

"Object reference not set to an instant of an object."

I cant find which object it is talking about whose reference is not set. Here is the code, if you can point out where am I wrong?

' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    	oDrawDoc = ThisApplication.ActiveDocument 
        
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
    	oSheet = oDrawDoc.ActiveSheet
		
		 ' Select a drawing view.
    Dim oDrawingView As DrawingView = ActiveSheet.View("FRONT").View
	
    ' Set a reference to the center of the base view.
    Dim oPoint As Point2d
    	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
	'oPoint.Y = oPoint.Y - oDrawingView.Height

   Dim oBox As Box2d
        Dim oCornerOne As Point2d
		oCornerOne = oBox.MinPoint
        oCornerOne.X = ActiveSheet.View("FRONT").Width * 0.1
        oCornerOne.Y = 0

        Dim oCornerTwo As Point2d
		oCornerTwo = oBox.MaxPoint
        oCornerTwo.X = ActiveSheet.View("FRONT").Width - 3 *0.1
        oCornerTwo.Y = 48 * 0.1

        ' Create the detail view with a rectangular box.
        Dim oDetailView As DetailDrawingView
        	oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
        kFromBaseDrawingViewStyle, False, oCornerOne, oCornerTwo, , 2, True , "F")
    'Else
        'MessageBox.Show("No arc was found in the selected drawing view.")
    'End If
0 Likes
Message 8 of 11

JhoelForshav
Mentor
Mentor

@sohaib.as01 

oBox is not set to anything... In the previous code I set it to the arcs rangebox....

You must create the corner points for your fence somehow. Before we used the rangebox of the arc to get its max and min points. I don't know what you want your detail view to contain so I cannot say how you should define these points...

Message 9 of 11

sohaib.as01
Advocate
Advocate

Oh okay, for that matter, I want my range box to contain the corners of my drawing view, so cant i tell Box2d object to go to that distance of my part to draw fence?

I have attached my pdf and .ipt and .idw drawing for better understanding.

Thank you so so very much for your help in making me understand where I am wrong @JhoelForshav 

0 Likes
Message 10 of 11

JhoelForshav
Mentor
Mentor
Accepted solution

@sohaib.as01 

I couldn't open your files completely because there were some missing references. Seems like you want circular fences though... Try this and let me know if you have any questions 🙂

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

'Set a reference to the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

' Select a drawing view.
Dim oDrawingView As DrawingView = ActiveSheet.View("FRONT").View

Dim oRadius As Double = .25


'Deatail view scale
Dim oScale As Double = 1.5
Dim oScaleFactor As Double = oScale/oDrawingView.Scale


Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

Dim oBorderBox As Box2d = oSheet.Border.RangeBox
Dim oPoint As Point2d
oPoint = oTG.CreatePoint2d(oBorderBox.MinPoint.X + oRadius * oScaleFactor, oDrawingView.Top - (oRadius * oScaleFactor / 2))


Dim oTopRight As Point2d = oTG.CreatePoint2d(oDrawingView.Left + oDrawingView.Width, oDrawingView.Top)
Dim oBottomRight As Point2d = oTG.CreatePoint2d(oTopRight.X, oTopRight.Y - oDrawingView.Height)
Dim oBottomLeft As Point2d = oTG.CreatePoint2d(oDrawingView.Left, oBottomRight.Y)
Dim oTopLeft As Point2d = oTG.CreatePoint2d(oBottomLeft.X, oTopRight.Y)


oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
kFromBaseDrawingViewStyle, True, oTopLeft, oRadius, , oScale, True, "A")

oPoint.Y = oPoint.Y - oRadius * oScaleFactor * 1.5

oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
kFromBaseDrawingViewStyle, True, oTopRight, oRadius, , oScale, True, "B")

oPoint.Y = oPoint.Y - oRadius * oScaleFactor * 1.5

oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
kFromBaseDrawingViewStyle, True, oBottomLeft, oRadius, , oScale, True, "C")

oPoint.Y = oPoint.Y - oRadius * oScaleFactor * 1.5

oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, _
kFromBaseDrawingViewStyle, True, oBottomRight, oRadius, , oScale, True, "D")

 

Message 11 of 11

sohaib.as01
Advocate
Advocate

Hey @JhoelForshav  Thank you so much for solving that problemof mine.

I needed rectangular fences btw, but I can now work that out myself now that you showed me how to actually place the drawing view fence. Works like a charm. Thanks man, as always, you are a gem 🙂

0 Likes