Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Automated section views in drawing

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
TechInventor20
896 Views, 12 Replies

Automated section views in drawing

Hello,

 

Currently i'm working on a set of codes in Ilogic that automate a drawing. But I got stuk on the part where I make the section views.

 

The work flow is;

- get some workpoints in the baseview (Topview)

- create lines between them

- Make the section views

- (part that does work but not all the way) rotate the section views.

 

 

This is where I start with;

TechInventor20_0-1634718509110.png

 

This is afther the section views are created;

TechInventor20_1-1634718592194.png

TechInventor20_2-1634718663216.png

 

Afther the rotating the section views are standing upside down or have the direction not in the right way (see picture below);

TechInventor20_3-1634718730080.png

 

 

This is how the direction of the section view should look like but I didn't figure out how to get there.... ( i want it to go counter clockwise);

TechInventor20_4-1634718809792.png

 

 

The code i have for rotating the view is this. maybe you can tweak it or use the variables etc. etc.

 

Dim oDrawingDocument As DrawingDocument = ThisServer.ActiveDocument
Dim oSheet As Sheet = oDrawingDocument.ActiveSheet

Dim oView2 As DrawingView = ActiveSheet.View("Aanzicht1").View

Dim oAssemblyDoc2 As AssemblyDocument = oView2.ReferencedDocumentDescriptor.ReferencedDocument

Dim oOccs2 As ComponentOccurrences
oOccs2 = oAssemblyDoc2.ComponentDefinition.Occurrences
Dim oOcc2 As ComponentOccurrence

For Each oOcc2 In oOccs2
	Totaltel = Totaltel + 1
Next 


Dim oOccs As ComponentOccurrences

oSketches = oView2.Sketches

'Variabelen------------------------
Dim Tel As Integer = 1 'als aantal schetsen/views
Dim Row As Integer = 4 'Rij voor aantal graden (excel)


For Each osketch In oSketches
	
Dim Viewletter As String = Chr(64 + Tel) 'Van getal naar letter (Voor sectionview naam.)


Dim oView As DrawingView = ActiveSheet.View(Viewletter).View
Dim oAssemblyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument


oOccs = oAssemblyDoc.ComponentDefinition.Occurrences
Dim oOcc As ComponentOccurrence






Dim Oviewtje As DrawingView 
'Oviewtje = oSheet.DrawingViews.Item(2)
Oviewtje = ActiveSheet.View(Viewletter).View

Dim Degrees As Integer = GoExcel.CellValue("C:\Users\Thomas\Desktop\TANK 3D.xlsx", "Romp", "D" & Row)
Degrees = 360 - Degrees + 90 
If Degrees > 360 Then
	Degrees = Degrees - 360
End If
rotatie_degrees = (Oviewtje.Rotation / PI * 180)

If rotatie_degrees*-1 = Degrees Or rotatie_degrees = Degrees Then
	Else
Oviewtje.RotateByAngle(Degrees * (PI / 180), True)
End If



'iLogicVb.RunRule("TESTING_EXTRA")
Dim teller As Integer = 1

For Each oOcc In oOccs
	
	Dim oComponentOcc As ComponentOccurrence = oAssemblyDoc.ComponentDefinition.Occurrences.Item(teller)
	If oComponentOcc.Name = "KW-02-00:1" Then
	xComponentOcc = oComponentOcc.Name.Replace(":1", "")
	
	For Each Nozzle1 As Document In oAssemblyDoc.ReferencedDocuments     
	
	Dim Nozzle2 As String = Nozzle1.DisplayName

	If Right(Nozzle2,3) = "ipt" Then
	xNozzle = Nozzle2.Replace(".ipt", "")
	Else
	xNozzle = Nozzle2.Replace(".iam", "")
	End If
	
''	Nozzle = oAssemblyDoc.ReferencedDocuments.Item(2)
''	Totaltel = Totaltel - 1
	If xNozzle = xComponentOcc Then 
		Nozzle = Nozzle1
	End If
	Next
	Dim oWorkPoint1 As WorkPoint = Nozzle.ComponentDefinition.WorkPoints.Item(1)
	oComponentOcc.CreateGeometryProxy(oWorkPoint1, oWorkPointProx1)
	Oviewtje.SetIncludeStatus(oWorkPointProx1, True)
	End If
	teller = teller + 1
Next
teller = 1
For Each oOcc In oOccs
	
	Dim oComponentOcc As ComponentOccurrence = oAssemblyDoc.ComponentDefinition.Occurrences.Item(teller)
	xComponentOcc = oComponentOcc.Name.Replace(":1", "")
	If xComponentOcc = "KW-06-" & Tel Then
	

	For Each Nozzle1 As Document In oAssemblyDoc.ReferencedDocuments     
	
	Dim Nozzle2 As String = Nozzle1.DisplayName

	
	If Right(Nozzle2,3) = "ipt" Then
	xNozzle = Nozzle2.Replace(".ipt", "")
	Else
	xNozzle = Nozzle2.Replace(".iam", "")
	End If
	
''	Nozzle = oAssemblyDoc.ReferencedDocuments.Item(2)

''	Totaltel = Totaltel - 1
	If xNozzle = xComponentOcc Then 
		Nozzle = Nozzle1
	End If
	Next
	Dim oWorkPoint2 As WorkPoint = Nozzle.ComponentDefinition.WorkPoints.Item(1)
	oComponentOcc.CreateGeometryProxy(oWorkPoint2, oWorkPointProx2)
	Oviewtje.SetIncludeStatus(oWorkPointProx2, True)
	End If
	teller = teller + 1
Next
	
''	Tel = Tel + 1


'	If Left(Nozzle.displayname, 5) = "KW-06" Then


'	End If
	
'	If Left(Nozzle.displayname, 5) = "KW-02" Then

'	Dim oWorkPoint2 As WorkPoint = Nozzle.ComponentDefinition.WorkPoints.Item(1)
'	oComponentOcc.CreateGeometryProxy(oWorkPoint2, oWorkPointProx2)
'	oView.SetIncludeStatus(oWorkPointProx2, True)
'	End If




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 oViewSection As SectionDrawingView
'oViewSection = oSheet.DrawingViews.Item(2)
oViewSection = ActiveSheet.View(Viewletter).View

If oCenterMark1.Position.X > oCenterMark2.Position.X Then
oViewSection.ReverseDirection
End If

Hoogte_nozzle = GoExcel.CellValue("C:\Users\Thomas\Desktop\TANK 3D.xlsx", "Romp", "F" & Row)
If Hoogte_nozzle - Hoogte_nozzle / 4 < oCenterMark2.Position.X*10 And oCenterMark2.Position.X*10 < Hoogte_nozzle + Hoogte_nozzle / 4 Then
	Else
		Oviewtje.RotateByAngle(Pie, True)
	End If
Oviewtje.RotateByAngle(Pie, True)

oView.SetIncludeStatus(oWorkPointProx1, False)
oView.SetIncludeStatus(oWorkPointProx2, False)

Tel = Tel + 1
Row = Row + 1

Next







I hope someone could help me and maybe have some fun with it. 

 

@JelteDeJong 

 

12 REPLIES 12
Message 2 of 13

The only thing that I need to get fixed is that the direction of the section view is in the right way and that the view is rotated like i showed in the pictures above. The rotation part works but not if the direction is reversed....

Message 3 of 13
Stakin
in reply to: TechInventor20

Are you want to add section as this way?

Stakin_0-1634800015447.png

 

Message 4 of 13
TechInventor20
in reply to: Stakin

Hi stakin,


That is indeed what I'm looking for. 

I have this rule that makes a section view of every sketch line in the drawing. 

TechInventor20_0-1634801419718.png

 

Afther running that rule i get the sectionviews but some of them are to the wrong direction. (see picture below)

Green is good direction and purple is the wrong direction.

TechInventor20_1-1634801511341.png

 

Now i am trying to change that but first I have to rotate every view. This because that looks much nicer. otherwise it looks like this;

TechInventor20_2-1634801612841.png

and i want them all  to align

 

 

 

Message 5 of 13
Stakin
in reply to: TechInventor20

the section direction is depend on the position of the section view

 

suggest you to put the section view to the temp position to be make a correct section direction

and then  rotate the view and  move it  to you want. 

Tags (1)
Message 6 of 13
TechInventor20
in reply to: Stakin

And how do you see that? because the section views that i make are in random order. 

Message 7 of 13
Stakin
in reply to: TechInventor20

DrawingViews.AddSectionView( ParentView As DrawingView, SectionLineSketch As DrawingSketch, Position As Point2d, ViewStyle As DrawingViewStyleEnum, [Scale] As Variant, [ShowLabel] As Boolean, [Name] As String, [Reserved] As Boolean, [FullDepth] As Boolean, [SectionDepth] As Variant ) As SectionDrawingView

 

The placement position determines the view direction.

The placement point is to the left of the section line and the section direction is to the left

Otherwise, vice versa

 

test it.

Message 8 of 13
TechInventor20
in reply to: Stakin

That part i'd understand, but how do i know wich one is to the left and to the right? how can i know that coordinates?

Message 9 of 13
Stakin
in reply to: TechInventor20

You can use the angle between the Y axis of the view and your section line

As your instance,it maybe

Dim oP1 As Point2d  ' Section Line Point in the cylinder 
Dim oP2 As Point2d  'Section Line Point the cylinder outer point
Dim oP3 As Point2d 'the section view first place position point


Dim oV1 As Vector2d
Dim oV2 As Vector2d

oV1 = ThisApplication.TransientGeometry.CreateVector2d(oP2.X - oP1.X, oP2.Y - oP1.Y)

oV2 = ThisApplication.TransientGeometry.CreateVector2d(0, If(oP1.X=0,1,Sign(oP1.X)))


oV1.AddVector(oV2)
oV1.ScaleBy(0.5)

oP3 = oP1.Copy
oP3.TranslateBy(oV1)

 

try it,untested,it may be cann't meet your demand

 

 

 

Message 10 of 13
TechInventor20
in reply to: Stakin

Thankyou for your time,

 

I will test this next week. im very busy right now. So youll hear from me soon

Message 11 of 13
Stakin
in reply to: Stakin

Try this,

Dim oP1 As Point2d
Dim oP2 As Point2d

Dim oV1 As Vector2d
Dim oV2 As Vector2d

	
oV1 = ThisApplication.TransientGeometry.CreateVector2d(oP2.X - oP1.X, oP2.Y - oP1.Y)

oV2 = ThisApplication.TransientGeometry.CreateVector2d(0, If(oP2.X=0,IIf(oP2.Y>=0,1,-1),Sign(oP2.X))*oV1.Length)

oV1.AddVector(oV2)
oV1.ScaleBy(0.5)
Dim oP3 As Point2d
oP3 = ThisApplication.TransientGeometry.CreatePoint2d((oP2.X + oP1.X)/2, (oP2.Y + oP1.Y)/2)
oP3.TranslateBy(oV1)
Message 12 of 13
TechInventor20
in reply to: Stakin

Morning,


Sorry I was occupied untill now, I tested it in a new ilogic rule, but I get the error message; "Object reference not set to an instance of an object." 

How do I implement this in my rule?

Message 13 of 13
Stakin
in reply to: TechInventor20

 

 

 

Dim oP1 As Point2d 'sectionline First point inside the cylinder
Dim oP2 As Point2d 'sectionline second point outside the cylinder 

Dim oV1 As Vector2d
Dim oV2 As Vector2d	
oV1 = ThisApplication.TransientGeometry.CreateVector2d(oP2.X - oP1.X, oP2.Y - oP1.Y)
oV2 = ThisApplication.TransientGeometry.CreateVector2d(0, If(oP2.X=0,IIf(oP2.Y>=0,1,-1),Sign(oP2.X))*oV1.Length)
oV1.AddVector(oV2)
oV1.ScaleBy(0.5)
Dim oP3 As Point2d
oP3 = ThisApplication.TransientGeometry.CreatePoint2d((oP2.X + oP1.X)/2, (oP2.Y + oP1.Y)/2)
oP3.TranslateBy(oV1)

 

 

 

Add this code snippet to your rule of create section view 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report