Placing drawing views collinear using ilogic

Placing drawing views collinear using ilogic

ysbaodnj
Enthusiast Enthusiast
349 Views
4 Replies
Message 1 of 5

Placing drawing views collinear using ilogic

ysbaodnj
Enthusiast
Enthusiast

Hi.

I want to place different model views on the same line by matching the height of the lower left corner.
If you use the alignment function, it will be aligned based on the center of the model view. (Refer to the picture below)

ysbaodnj_0-1678068082194.png

Is there a way to sort it like the picture below?

ysbaodnj_1-1678068101856.png

 

0 Likes
350 Views
4 Replies
Replies (4)
Message 2 of 5

matt_jlt
Collaborator
Collaborator

Nothing that i know of that is built in. I have written an addin ages ago that does this.

 

What i had to do was to get the user to select a line in each view, get the Y axis position of one end point in each of the lines, work out the difference between them and then move one of the views up / down to suit that difference.

 

I dont have to code readily available but that is the summary of what i did.

0 Likes
Message 3 of 5

lmc.engineering
Advocate
Advocate

You just need to offset the view based on the difference in view heights:

Private Function OffsetVal(DatumView As DrawingView, ViewX As DrawingView) As Double
	Dim DViewHeight As Double = DatumView.Height
	Dim ViewXHeight As Double = ViewX.Height
	Dim Offset As Double
	If DViewHeight <> ViewXHeight Then
		Offset = (ViewXHeight - DViewHeight) / 2
	Else
		Offset = 0
	End If	
	Return Offset
End Function

1. Place your first view

2. Place your second view

3. Pass views to function

4. Reposition second view accordingly

 

 

 

0 Likes
Message 4 of 5

JMGunnar
Collaborator
Collaborator

Try this 

 

Sub Main()
	Dim oDoc As DrawingDocument
	oDoc = ThisDoc.Document

	Dim oCurve1, oCurve2 As DrawingCurveSegment
	oCurve1 = GetCurve1(oDoc)
	oCurve2 = GetCurve2(oDoc)

	Dim oView1, oView2 As DrawingView
	oView1 = oCurve1.Parent.Parent
	oView2 = oCurve2.Parent.Parent

	Dim Curve1Point1, Curve1Point2, Curve2Point1, Curve2Point2, View1Point, View2Point As Point2d
	Curve1Point1=oCurve1.StartPoint
	Curve1Point2=oCurve1.EndPoint
	Curve2Point1=oCurve2.StartPoint
	Curve2Point2=oCurve2.EndPoint

	If oView1.Name = oView2.Name Then
		MessageBox.Show("Select lines from different views", "Align view error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		Exit Sub
	End If

	If (Round((Curve1Point1.X - Curve1Point2.X)*1e8) = 0 And Round((Curve2Point1.X - Curve2Point2.X)*1e8) = 0) Then
		MoveView = Curve1Point1.X - Curve2Point1.X
		oView2Point = oView2.Position
		oView2Point.X = oView2Point.X + MoveView
		oView2.Position = oView2Point
	Else If(Round((Curve1Point1.Y - Curve1Point2.Y)*1e8) = 0 And Round((Curve2Point1.Y - Curve2Point2.Y)*1e8) = 0) Then
		MoveView = Curve1Point1.Y - Curve2Point1.Y
		oView2Point = oView2.Position
		oView2Point.Y = oView2Point.Y + MoveView
		oView2.Position = oView2Point
	Else
		MessageBox.Show("Lines are not horizontal or vertical or not in the same orientation.", "Align view error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		MsgBox(Curve1Point1.Y - Curve1Point2.Y)
		MsgBox(Curve2Point1.Y - Curve2Point2.Y)
		Exit Sub
	End If
End Sub

Private Function GetCurve1(ByVal oDoc As DrawingDocument) As DrawingCurveSegment
	Dim Curve As DrawingCurveSegment
	Curve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select first line to align")
	Return Curve
End Function

Private Function GetCurve2(ByVal oDoc As DrawingDocument) As DrawingCurveSegment
	Dim Curve As DrawingCurveSegment
	Curve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select second line to align")
	Return Curve
End Function
0 Likes
Message 5 of 5

Cadkunde.nl
Collaborator
Collaborator

I looked up some old code i made years ago for a customer.

First I have a script that adds views to different Sheets. (flatpatterns of steel 10mm had to go to a sheet called steel 10mm) And added overall dimensions and notes.

 

After all views were made, I used this to position them with this code.

Starting lower left, placing next view on the right.

Untill there was not enough space on the right, it would start again on the left on a new row:

 

Dim oTG As TransientGeometry = oApp.TransientGeometry

 

'position views
For Each oSheet As Sheet In CutDrawing.Sheets
oSheet.Activate()
Dim posX As Double = 1
Dim posY As Double = 0
Dim heightY As Double = 1
Dim LargestY As Double = 0
Dim SheetWidth As Double = 83.5 'cm

 

For Each oView As DrawingView In oSheet.DrawingViews
'New Line
If posX + oView.Width > SheetWidth Then
heightY = heightY + LargestY + 5
LargestY = 0
posX = 1
End If

'Point is in the center, with this i calc dist to lower left
posX = posX + oView.Width / 2 + 1
posY = heightY + oView.Height / 2 + 1

If oView.Height > LargestY Then LargestY = oView.Height
oPoint1 = oTG.CreatePoint2d(posX, posY)
oView.Position = oPoint1
posX = posX + oView.Width / 2 + 1
Next
Next

0 Likes