### Author Topic: Midpoint of offset line  (Read 8412 times)

0 Members and 1 Guest are viewing this topic.

#### Nima2018

• Newt
• Posts: 30
##### Midpoint of offset line
« on: January 15, 2019, 10:16:21 AM »
Hi
I want get coordinates of midpoint of a line that created by offset via code ( in my code lineObj2 ) :

Code: [Select]
`    Dim lineObj2 As Variant                lineObj2 = lineObj.Offset(2 * Round(lineObj.Length, 2))`How can i do this ?
Please advice me .

#### Nima2018

• Newt
• Posts: 30
##### Re: Midpoint of offset line
« Reply #1 on: January 15, 2019, 11:46:44 AM »
Hi

I could solve the problem using the following code :

Code: [Select]
`    Dim lineObj2 As Variant, lineObj3 As AcadLine     lineObj2 = lineObj.Offset(2 * Round(lineObj.Length, 2))          Dim ent As AcadEntity       Set ent = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)             If ent.ObjectName = "AcDbLine" Then                    Set lineObj3 = ent                    ent.Highlight True                       Dim AA As Variant                       Dim BB As Variant                       Dim CC As Variant                          AA = lineObj3.startPoint                          BB = lineObj3.endPoint                          CC(0) = (AA(0) + BB(0)) * 0.5                          CC(1) = (AA(1) + BB(1)) * 0.5                          CC(2) = (AA(2) + BB(2)) * 0.5                          Debug.Print CC(0), CC(1), CC(2)                   Else            End If`
But I think there's a better way,So please say if you have a better suggestion.

#### BIGAL

• Swamp Rat
• Posts: 1446
• 40 + years of using Autocad
##### Re: Midpoint of offset line
« Reply #2 on: April 21, 2019, 07:17:18 PM »
That looks ok the only other way is via using angle and distance of a line.
A man who never made a mistake never made anything

#### RICVBA

• Newt
• Posts: 62
##### Re: Midpoint of offset line
« Reply #3 on: August 14, 2019, 12:14:43 PM »
you could use an AcadLine object instead of a Variant and get its midpoint:

Code: [Select]
`    Dim lineObj2 As AcadLine    Set lineObj2 = lineObj.Offset(-2 * Round(lineObj.Length, 2))(0) ' <-- get the first element of then variant spitted out of Offset method and set it to a line object (because you know it really is!)       Dim midPoint2(0 To 2) As Double    With lineObj2        midPoint2(0) = (.startPoint(0) + .endPoint(0)) * 0.5        midPoint2(1) = (.startPoint(1) + .endPoint(1)) * 0.5        midPoint2(2) = (.startPoint(2) + .endPoint(2)) * 0.5    End With`