create a section view from my base view using i logic

create a section view from my base view using i logic

suresh.r.ext
Contributor Contributor
1,054 Views
4 Replies
Message 1 of 5

create a section view from my base view using i logic

suresh.r.ext
Contributor
Contributor

i just tring to create a section view from my base view . im looking for te code. can any one help me with code.

 

 

view1 --> section line  direction ---> distance ----> generare view

 

sureshrext_0-1697533687973.png

 

 

thanks in advance

0 Likes
Accepted solutions (1)
1,055 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor

Hi @suresh.r.ext,

 

Here is some informations related to creating section views using the API : Inventor 2024 Help | DrawingViews.AddSectionView Method | Autodesk

You need to create a drawing sketch first on the main drawing view, draw the section line & then only create the section view. About this sketch, will it  be already drawn? Or do we need to code it ? Where will it be ? Can you provide pictures of the derired result ?


Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @suresh.r.ext 

 

I had this example on hand. Note that this does some conversion from cm to inch that might not be needed for your work. It also breaks the view alignment, but you can remove that if not needed.

 

See attached Inventor 2023 files.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

 

Sub Main
	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

	Dim oUOM As UnitsOfMeasure = oDrawDoc.UnitsOfMeasure
	oInvUnits = UnitsTypeEnum.kCentimeterLengthUnits
	oCnvt_cm_to_in = oUOM.ConvertUnits(1, oUOM.LengthUnits, oInvUnits) 'cm to inch (2.54)
	oCnvt_in_to_cm = oUOM.ConvertUnits(1, oInvUnits, oUOM.LengthUnits) 'inch to cm (.3937...)

	'get the sheet
	Dim oSheet As Sheet
	oSheet = oDrawDoc.ActiveSheet

	'get base view
	Dim oBaseView As DrawingView
	oBaseView = oSheet.DrawingViews.Item(1)

	Dim SketchName As String = "Section Sketch"
	Dim SectionViewName As String = "Z"

	'[ delete section view if it already exits
	For Each View As DrawingView In oSheet.DrawingViews

		'delete view from previous try if it exists
		If View.name = SectionViewName Then
			Try : View.Delete : Catch : End Try
		End If

		'delete sketch if it already exits
		Try : oBaseView.Sketches.Item(SketchName).Delete : Catch : End Try
	Next
	']

	Dim SectionSketch As DrawingSketch = oBaseView.Sketches.Add
	SectionSketch.Edit

	viewExtendPercent = 0.05
	Left_X = oBaseView.Center.X - (oBaseView.Width / 2) -(oBaseView.Width * viewExtendPercent)
	Right_X = oBaseView.Center.X + (oBaseView.Width / 2) + (oBaseView.Width * viewExtendPercent)

	Dim SectionPoint_L As Point2d = oTG.CreatePoint2d(Left_X, oBaseView.Center.Y)
	Dim SectionPoint_R As Point2d = oTG.CreatePoint2d(Right_X, oBaseView.Center.Y)
	Dim SheetPoint_L As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_L)
	Dim SheetPoint_R As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_R)
	Dim SketchLine As Inventor.SketchLine = SectionSketch.SketchLines.AddByTwoPoints(SheetPoint_L, SheetPoint_R)

	SectionSketch.ExitEdit
	SectionSketch.Name = SketchName

	'section view placement point 
	'the X is intially ignored because of the view alignment, but we reuse this point after alignment is broken
	Dim ViewCenterPoint As Point2d = oTG.CreatePoint2d(oBaseView.Center.X + 10, oBaseView.Center.Y + oBaseView.Height)

	Dim SectionView As Inventor.SectionDrawingView
	SectionView = oSheet.DrawingViews.AddSectionView(oBaseView, SectionSketch, ViewCenterPoint,
	DrawingViewStyleEnum.kFromBaseDrawingViewStyle, , , SectionViewName)
	SectionView.Aligned = False 'break alignement
	SectionView.Center = ViewCenterPoint 'move view

	SectionView.ReverseDirection
End Sub

 

 

EESignature

Message 4 of 5

suresh.r.ext
Contributor
Contributor

@Curtis_WaguespackThanks it helps 😍

0 Likes
Message 5 of 5

est_david_bermudez
Contributor
Contributor

Hi @Curtis_Waguespack and everyone.

 

I'm working on creating a section view using the code below. However, I need to crop it in a specific way, as shown in the attached images.

Does anyone know how I can make this crop in the section view?

I was considering using a work point that I already have in one of the parts (Point2), which is located exactly in the center of the connection I want to section. 

 

I appreciate any suggestions or ideas. Thanks!

 

 

Class Detalles
	Public oDrawDoc As DrawingDocument 
	Public oTG As TransientGeometry
	'get the sheet
	Public oSheet As Sheet
	'get base view
	Public oBaseView As DrawingView
	
	Public SketchName As String 
	Public SectionViewName As String 
	Public oPartDoc As AssemblyDocument
	
	Sub Main()
		
		oDrawDoc = ThisApplication.ActiveDocument
		oTG = ThisApplication.TransientGeometry
		oSheet = oDrawDoc.ActiveSheet
		oBaseView = oSheet.DrawingViews.Item(3)
		SketchName  = "Section Sketch"
		SectionViewName  = "Z"
		
		'VistaDetalle()
		
		VistaSeccion()
	End Sub
	
'	Sub VistaDetalle()
		
'	End Sub
	
	Sub VistaSeccion()
	
		'[ delete section view if it already exits
		For Each View As DrawingView In oSheet.DrawingViews
	
			'delete view from previous try if it exists
			If View.name = SectionViewName Then
				Try : View.Delete : Catch : End Try
			End If
	
			'delete sketch if it already exits
			Try : oBaseView.Sketches.Item(SketchName).Delete : Catch : End Try
		Next
		']
	
		Dim SectionSketch As DrawingSketch = oBaseView.Sketches.Add
		SectionSketch.Edit
	
		viewExtendPercent = 0.05
		Dim angulo As Double = 170
		X = oBaseView.Center.X + (6 * Cos((3.1416/180)*angulo))
		Y = oBaseView.Center.Y + (6 * Sin((3.1416/180)*angulo))
	
		Dim SectionPoint_L As Point2d = oTG.CreatePoint2d(oBaseView.Center.X, oBaseView.Center.Y)
		Dim SectionPoint_R As Point2d = oTG.CreatePoint2d(X, Y)
		Dim SheetPoint_L As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_L)
		Dim SheetPoint_R As Point2d = SectionSketch.SheetToSketchSpace(SectionPoint_R)
		Dim SketchLine As Inventor.SketchLine = SectionSketch.SketchLines.AddByTwoPoints(SheetPoint_L, SheetPoint_R)
	
		SectionSketch.ExitEdit
		SectionSketch.Name = SketchName
	
		'section view placement point 
		'the X is intially ignored because of the view alignment, but we reuse this point after alignment is broken
		Dim ViewCenterPoint As Point2d = oTG.CreatePoint2d(oBaseView.Center.X + 10, oBaseView.Center.Y + oBaseView.Height)
	
		Dim SectionView As Inventor.SectionDrawingView
		SectionView = oSheet.DrawingViews.AddSectionView(oBaseView, SectionSketch, ViewCenterPoint,
		DrawingViewStyleEnum.kFromBaseDrawingViewStyle, , , SectionViewName)
		SectionView.Aligned = False 'break alignement
		SectionView.Center = ViewCenterPoint 'move view
	
		SectionView.ReverseDirection
		
		Dim rotacion As Double
		
		If angulo > 37 And angulo < 270 Then
			rotacion = (3.1416 / 180) * (angulo - 180)
		Else
			rotacion = (3.1416 / 180) * (angulo)
		End If
		
		SectionView.RotateByAngle(rotacion, True)
	End Sub

End Class

 

 

est_david_bermudez_2-1740511930733.png

est_david_bermudez_3-1740512112623.png

 

 

 

 

0 Likes