You are on page 1of 13

Cont our Li nes.

vb
' I mpor t s
I mpor t s Syst em
I mpor t s Aut odesk. Aut oCAD
I mpor t s Aut odesk. Aut oCAD. Appl i cat i onSer vi ces
I mpor t s
Aut odesk. Aut oCAD. Appl i cat i onSer vi ces. Appl i cat i on
I mpor t s Aut odesk. Aut oCAD. Dat abaseSer vi ces
I mpor t s Aut odesk. Aut oCAD. Edi t or I nput
I mpor t s Aut odesk. Aut oCAD. Geomet r y
I mpor t s Aut odesk. Aut oCAD. Layer Manager
I mpor t s Aut odesk. Aut oCAD. Runt i me
I mpor t s Aut odesk. Aut oCAD. Wi ndows
I mpor t s St r uct ur al CAD. myShar edMet hods
Publ i c Cl ass Lvt AcadCommands
<CommandMet hod( " Cont our Li nes" ) > _
Publ i c Sub Cont our Li nes( )
Di mcur Doc As Document =
Document Manager . Mdi Act i veDocument
Di mcur Ed As Edi t or = cur Doc. Edi t or
Di muser Boundar yPoi nt s As Poi nt 3dCol l ect i on =
Get User Boundar yPoi nt s( cur Ed)
I f user Boundar yPoi nt s = Not hi ng Then Exi t Sub
' Debug. Wr i t eLi ne( vbLf & " You have sel ect ed t he
f ol l owi ng Boundar y Poi nt s: " )

' Gener al Funct i ons1. DebugWr i t ePt Col l ( user Boundar yPoi nt s)
Di muser I ncl i nedPl ane As Pl ane =
Get User I ncl i nedPl ane( cur Ed)
I f user I ncl i nedPl ane = Not hi ng Then Exi t Sub
I f
user I ncl i nedPl ane. Nor mal . I sPar al l el To( Vect or 3d. ZAxi s)
Then
' When t he " I ncl i ned" pl ane i s
hor i zont al , t hen t er mi nat e gr acef ul l y.
Di mXYOr i gi nOnPl ane As Poi nt 3d =
user I ncl i nedPl ane. I nt er sect Wi t h(

New Li ne3d( Poi nt 3d. Or i gi n,
Page 1
Cont our Li nes. vb
Vect or 3d. ZAxi s) ) . Get Val ue( 0)
MsgBox( " Your Pl ane i s hor i zont al . " & vbCr
& _
St r i ng. For mat ( " El evat i on i s
{0: 0. 000}. " , XYOr i gi nOnPl ane. Z) )
Exi t Sub
El se
' Pr oj ect user boundar y poi nt s on
i ncl i ned pl ane i n ZAxi s di r ect i on
Di mpr oj ect edBoundar yPoi nt s As
Poi nt 3dCol l ect i on =

Pr oj ect Poi nt sOnPl ane( user Boundar yPoi nt s,
user I ncl i nedPl ane, Vect or 3d. ZAxi s)
' Debug. Wr i t eLi ne( vbLf & " The f ol l owi ng ar e
t he pr oj ect i ons of your Boundar y Poi nt s: " )

' Gener al Funct i ons1. DebugWr i t ePt Col l ( pr oj ect edBoundar yPo
i nt s)
' Get Mi n/ Max Boundar y El evat i ons
[ boundi ngEl evat i ons( 0) / ( 1) ]
Di mboundi ngEl evat i ons( ) As Doubl e =
Get Boundi ngEl evat i ons( pr oj ect edBoundar yPoi nt s)
MsgBox( St r i ng. For mat ( " Mi n/ Max El evat i ons
ar e {0: 0. 000}/ {1: 0. 000}. " ,
boundi ngEl evat i ons( 0) ,
boundi ngEl evat i ons( 1) ) & vbLf & _
" Pl ease sel ect any posi t i ve
El evat i on st ep f or I sol i nes. . . " )
' Cal cul at e Di scr et e I sol i ne El evat i ons
usi ng User St ep sel ect i on
Di mi sol i neEl evat i ons As Li st ( Of Doubl e) =
Get Di scr et eVal uesBySt ep( cur Ed,
boundi ngEl evat i ons)
' Get Ent i t yLi st pr oduces a l i st of
i sol i nes and DBText s
' f r ompr oj ect edBoundar yPoi nt s and
i sol i neEl evat i ons.
Di mi sol i neEnt i t i es As Li st ( Of Ent i t y) =
Get Ent i t yLi st ( pr oj ect edBoundar yPoi nt s,
Page 2
Cont our Li nes. vb
i sol i neEl evat i ons)
AddToModel Space( cur Doc. Dat abase,
i sol i neEnt i t i es)
End I f
End Sub
Funct i on Get User Boundar yPoi nt s( ByVal edi t or I n As
Edi t or ) As Poi nt 3dCol l ect i on
' I ni t i al i zi ng User Boundar y Poi nt s Col l ect i on
Di muser BPt sCol l As New Poi nt 3dCol l ect i on
Di muser PPR As Pr ompt Poi nt Resul t
Di muser PPO As New Pr ompt Poi nt Opt i ons( " Sel ect
Boundar y Poi nt s: " )
user PPO. Al l owNone = Tr ue
Di mi As I nt eger = 0
Di muser BLi ne As New Geomet r y. Li ne3d
Di muser BPl ane As Geomet r y. Pl ane = Not hi ng
Di msameLi neFl ag As Bool ean = Tr ue
Di mver t i cal Pl aneFl ag As Bool ean = Tr ue
Do
user PPR = edi t or I n. Get Poi nt ( user PPO)
Sel ect Case user PPR. St at us
Case Pr ompt St at us. OK
Di muser NewBPt As Poi nt 3d =
user PPR. Val ue
i += 1
user BPt sCol l . Add( user PPR. Val ue)
user PPO. Message = vbCr & " Sel ect
anot her poi nt / Ent er t o f i ni sh: "
Sel ect Case i
Case 2
user BLi ne = New
Geomet r y. Li ne3d( user BPt sCol l . I t em( 0) ,
user BPt sCol l . I t em( 1) )
Case I s >= 3
I f sameLi neFl ag Then
' means al l
pr evi ousl y sel ect ed poi nt s ar e on same l i ne:

CheckNewPoi nt For Pl aneConst r uct ( user BPt sCol l . I t em( 0) ,
Page 3
Cont our Li nes. vb
user BPt sCol l . I t em( 1) ,

user PPR. Val ue, user BPl ane,

sameLi neFl ag, ver t i cal Pl aneFl ag)
El se ' Meani ng a pl ane
has al r eady been def i ned:
I f ver t i cal Pl aneFl ag
Then
I f
user BPl ane. I sOn( user PPR. Val ue, New Tol er ance( 1. 0, 1. 0) )
= Fal se Then

ver t i cal Pl aneFl ag = Fal se
End I f
End I f
End I f
End Sel ect
Case Pr ompt St at us. None
I f i < 3 Then
user PPO. Message = vbCr & " Needs
at l east 3 Boundar y poi nt s. " & _
vbCr &
St r i ng. For mat ( " Pl ease sel ect at l east {0} mor e
poi nt s. " , 3 - i )
MsgBox( " Needs at l east 3
Boundar y poi nt s. " & _
vbCr &
St r i ng. For mat ( " Pl ease sel ect at l east {0} mor e
poi nt s. " , 3 - i ) )
El seI f sameLi neFl ag Then
user PPO. Message = vbCr & " Al l
poi nt s ar e on t he same Li ne. " & _
vbCr & " Pl ease sel ect at
l east one mor e poi nt out si de t hi s l i ne. "
MsgBox( " Al l poi nt s ar e on t he
same Li ne. " & _
vbCr & " Pl ease sel ect at
l east one mor e poi nt out si de t hi s l i ne. " )
El seI f ver t i cal Pl aneFl ag Then
user PPO. Message = vbCr & " Al l
poi nt s ar e on a ver t i cal pl ane. " & _
vbCr & " Pl ease sel ect at
Page 4
Cont our Li nes. vb
l east one mor e poi nt out si de t hi s pl ane. "
MsgBox( " Al l poi nt s ar e on a
ver t i cal pl ane. " & _
vbCr & " Pl ease sel ect at
l east one mor e poi nt out si de t hi s pl ane. " )
El se
MsgBox( " Your Boundar y i s OK. " )
Exi t Do
End I f
Case Pr ompt St at us. Cancel
MsgBox( " Exi t i ng Command. " )
Ret ur n Not hi ng
End Sel ect
Loop
Ret ur n user BPt sCol l
End Funct i on
Sub CheckNewPoi nt For Pl aneConst r uct ( ByVal pt 1 As
Poi nt 3d, ByVal pt 2 As Poi nt 3d, ByVal newPt As Poi nt 3d,
ByRef pl aneI n As
Pl ane, ByRef sameLi neFl agI n As Bool ean, ByRef
ver t i cal Pl aneFl agI n As Bool ean)
Di ml i ne1 As New Li ne3d( pt 1, pt 2)
I f l i ne1. I sOn( newPt , New Tol er ance( 1. 0, 1. 0) ) =
Fal se Then
' Meani ng cur r ent poi nt i s out si de t he
l i ne ( t hi s i s good! ) , and
' now a pl ane can be def i ned and checked
f or per pendi cul ar i t y:
sameLi neFl agI n = Fal se
pl aneI n = New Geomet r y. Pl ane( pt 1, pt 2,
newPt )
I f
Mat h. Abs( pl aneI n. Nor mal . Dot Pr oduct ( Vect or 3d. ZAxi s) ) >
0. 1 Then
' Meani ng pl ane i s *not * ver t i cal ,
whi ch i s good!
ver t i cal Pl aneFl agI n = Fal se
End I f
End I f
End Sub
Funct i on Get User I ncl i nedPl ane( ByVal edi t or I n As
Page 5
Cont our Li nes. vb
Edi t or ) As Pl ane
' t he goal of t hi s f unct i on i s t o r et ur n a
non- ver t i cal Pl ane.
' I ni t i al i zi ng User Pl ane.
Di muser I ncPl ane As Geomet r y. Pl ane = Not hi ng
Di muser PPR As Pr ompt Poi nt Resul t
Di muser PPO As New Pr ompt Poi nt Opt i ons( " Sel ect
t hr ee Poi nt s def i ni ng a non- ver t i cal Pl ane: " & _
vbCr &
" Pl ease sel ect t he f i r st poi nt : " )
user PPO. Al l owNone = Fal se
Di muser PDR As Pr ompt Doubl eResul t
Di muser PDO As New Pr ompt Doubl eOpt i ons( " " )
Wi t h user PDO
. Message = " Ent er poi nt El evat i on: "
. Al l owNone = Fal se
. UseDef aul t Val ue = Tr ue
. Def aul t Val ue = 0
End Wi t h
Di mi As I nt eger = 0
Di mpl anePt 1 As New Poi nt 3d
Di mpl anePt 2 As New Poi nt 3d
Di muser Li ne As New Geomet r y. Li ne3d
Do
user PPR = edi t or I n. Get Poi nt ( user PPO)
Sel ect Case user PPR. St at us
Case Pr ompt St at us. OK
user PDO. Def aul t Val ue =
user PPR. Val ue. Z
user PDR =
edi t or I n. Get Doubl e( user PDO)
Sel ect Case user PDR. St at us
Case Pr ompt St at us. OK
Di mnewPoi nt ToBeTest ed As
New Poi nt 3d(
user PPR. Val ue. X,
user PPR. Val ue. Y, user PDR. Val ue)
Sel ect Case i
Case 0
pl anePt 1 =
newPoi nt ToBeTest ed
Page 6
Cont our Li nes. vb
user PPO. Message =
" Pl ease sel ect t he second poi nt : "
i += 1
Case 1
I f
newPoi nt ToBeTest ed. I sEqual To( pl anePt 1) Then
user PPO. Message
= " You' ve al r eady chosen t hat poi nt . " & vbCr & _
" Pl ease
r esel ect t he second poi nt : "
El se
pl anePt 2 =
newPoi nt ToBeTest ed
user Li ne = New
Li ne3d( pl anePt 1, pl anePt 2)
user PPO. Message
= " Pl ease sel ect t he l ast poi nt : "
i += 1
End I f
Case 2
I f
user Li ne. I sOn( newPoi nt ToBeTest ed) Then
user PPO. Message
= " Your t hi r d poi nt shoul d be out si de t he l i ne " & vbCr
& _
" Pl ease
r esel ect t he l ast poi nt : "
El se
user I ncPl ane =
New Pl ane( pl anePt 1, pl anePt 2, newPoi nt ToBeTest ed)

' Debug. Wr i t eLi ne( vbLf & " Poi nt s sel ect ed f or I ncl i ned
Pl ane def i ni t i on: " )

' Gener al Funct i ons1. DebugWr i t ePt Col l (
' New
Poi nt 3dCol l ect i on( {pl anePt 1, pl anePt 2,
newPoi nt ToBeTest ed}) )
I f
Mat h. Abs( user I ncPl ane. Nor mal . Dot Pr oduct ( Vect or 3d. ZAxi s)
) < 0. 1 Then

Page 7
Cont our Li nes. vb
user PPO. Message = " Your poi nt s ar e on a ver t i cal
pl ane. " & vbCr & _
" Pl ease
r esel ect t he l ast poi nt : "
El se
' Meani ng
pl ane i s *not * ver t i cal , whi ch i s good!
i += 1 '
now i = 3 and we wi l l exi t t he Do- Loop.
End I f
End I f
End Sel ect
Case Pr ompt St at us. Cancel
MsgBox( " Exi t i ng Command. " )
Ret ur n Not hi ng
End Sel ect
Case Pr ompt St at us. Cancel
MsgBox( " Exi t i ng Command. " )
Ret ur n Not hi ng
End Sel ect
Loop Unt i l i = 3
Ret ur n user I ncPl ane
End Funct i on
Funct i on Get Boundi ngEl evat i ons( ByVal poi nt 3dCol l As
Poi nt 3dCol l ect i on) As Doubl e( )
Di mmi nZ As Doubl e = poi nt 3dCol l ( 0) . Z
Di mmaxZ As Doubl e = poi nt 3dCol l ( 0) . Z
For Each poi nt I nst ance As Poi nt 3d I n
poi nt 3dCol l
I f poi nt I nst ance. Z < mi nZ Then
mi nZ = poi nt I nst ance. Z
End I f
I f poi nt I nst ance. Z > maxZ Then
maxZ = poi nt I nst ance. Z
End I f
Next
Ret ur n {mi nZ, maxZ}
End Funct i on
Funct i on Get Ent i t yLi st ( ByVal poi nt s As
Poi nt 3dCol l ect i on,
Page 8
Cont our Li nes. vb
ByVal el evat i ons As Li st ( Of
Doubl e) ) As Li st ( Of Dat abaseSer vi ces. Ent i t y)
' I t er at e t hr ough I sol i ne El evat i ons.
' For each El evat i on,
' usi ng pr oj ect edBoundar yPoi nt s and
I nt er sect Pol ygonPl ane,
' add t he El evat i on' s I sol i ne and Text t o
Ent i t y Li st .
Di mi soEnt i t i es As New Li st ( Of
Dat abaseSer vi ces. Ent i t y)
For Each el evat i on As Doubl e I n el evat i ons
Di mel evat i onPl ane As New Pl ane( New
Poi nt 3d( 0, 0, el evat i on) , Vect or 3d. ZAxi s)
' Def i ne a col l ect i on f or i nt er sect i on
poi nt s on each el evat i on
Di mi soI nt Poi nt s As New Poi nt 3dCol l ect i on
Di mpt 1 As New Poi nt 3d
Di mpt 2 As New Poi nt 3d
Di mel evat i onText As New
Dat abaseSer vi ces. DBText
Wi t h el evat i onText
. Posi t i on = Poi nt 3d. Or i gi n
. Hei ght = 0. 4
. Ver t i cal Mode =
Text Ver t i cal Mode. Text Bot t om
. Hor i zont al Mode =
Text Hor i zont al Mode. Text Cent er
. Rot at i on = 0
End Wi t h
Di mi sol i ne As New Dat abaseSer vi ces. Li ne
Di mel evat i onToZer o As New Mat r i x3d
el evat i onToZer o = Mat r i x3d. Di spl acement ( New
Vect or 3d( 0, 0, - el evat i on) )
i soI nt Poi nt s =
I nt er sect Pol ygonPl ane( poi nt s, el evat i onPl ane)
' Debug. Wr i t eLi ne( vbLf &
St r i ng. For mat ( " i soI nt Poi nt s f or el evat i on {0: 0. 000}: " ,
el evat i on. ToSt r i ng) )

' Gener al Funct i ons1. DebugWr i t ePt Col l ( i soI nt Poi nt s)
I f i soI nt Poi nt s. Count > 0 Then
Page 9
Cont our Li nes. vb
pt 1 = i soI nt Poi nt s. I t em( 0)
' Di mel evat i onSt r i ng As St r i ng =
St r i ng. For mat ( " {0: 0. 000}" , el evat i on. ToSt r i ng)
el evat i onText . Text St r i ng =
el evat i on. ToSt r i ng( " F3" )
Sel ect Case i soI nt Poi nt s. Count
Case 1
el evat i onText . Al i gnment Poi nt =
pt 1. Tr ansf or mBy( el evat i onToZer o)
i soEnt i t i es. Add( el evat i onText )
Case I s > 1
pt 2 = i soI nt Poi nt s. I t em( 1)
' Debug. Wr i t eLi ne( pt 1. ToSt r i ng &
vbTab & pt 2. ToSt r i ng)
Di mi soLi neSeg As New
Geomet r y. Li neSegment 3d( pt 1, pt 2)
i sol i ne. St ar t Poi nt = pt 1
i sol i ne. EndPoi nt = pt 2

i sol i ne. Tr ansf or mBy( el evat i onToZer o)
i soEnt i t i es. Add( i sol i ne)
el evat i onText . Al i gnment Poi nt =
i soLi neSeg. Mi dPoi nt . Tr ansf or mBy( el evat i onToZer o)

' Debug. Wr i t eLi ne( el evat i onText . Posi t i on. ToSt r i ng)
el evat i onText . Rot at i on =
Fi xText Rot at i onAngl e(

i soLi neSeg. Di r ect i on. Angl eOnPl ane( el evat i onPl ane) )
i soEnt i t i es. Add( el evat i onText )
' el evat i onText . Posi t i on =
'
pt 1. Add( pt 1. Get Vect or To( pt 2) . Di vi deBy( 2) )
' el evat i onText . Rot at i on =
'
pt 1. Get Vect or To( pt 2) . Angl eOnPl ane( el evat i onPl ane)
End Sel ect
End I f
Next
Ret ur n i soEnt i t i es
Page 10
Cont our Li nes. vb
End Funct i on
' Fol l owi ng ar e Test Subs :
<CommandMet hod( " Test Get user I ncl i nedPl ane" ) > _
Publ i c Sub Test Get user I ncl i nedPl ane( )
Di mcur Doc As Document =
Document Manager . Mdi Act i veDocument
Di mcur Ed As Edi t or = cur Doc. Edi t or
Di muser I ncl i nedPl ane As Pl ane
user I ncl i nedPl ane = Get User I ncl i nedPl ane( cur Ed)
MsgBox( user I ncl i nedPl ane. Nor mal . ToSt r i ng)
End Sub
<CommandMet hod( " Test Get I nt er medi at eVal ues" ) > _
Publ i c Sub Test Get I nt er medi at eVal ues( )
Di mi sol i neEl evat i ons As Li st ( Of Doubl e) =
Get I nt er medi at eVal ues( - 2. 5,

8. 5,

1)
For Each i sol i neEl evat i on As Doubl e I n
i sol i neEl evat i ons
Debug. Wr i t eLi ne( St r i ng. For mat ( " {0: 0. 000}" ,
i sol i neEl evat i on) )
Next
End Sub
<CommandMet hod( " Test I nt er sect Wi t h" ) > _
Publ i c Sub Test I nt er sect Wi t h( )
Di mmyPL As New Pol yl i ne
Wi t h myPL
. Cl osed = Tr ue
. AddVer t exAt ( 0, New Poi nt 2d( 0, 0) , 0, 0, 0)
. AddVer t exAt ( 1, New Poi nt 2d( 4, 4) , 0, 0, 0)
. AddVer t exAt ( 2, New Poi nt 2d( 8, 0) , 0, 0, 0)
End Wi t h
Di mmyRot PL As Pol yl i ne = myPL. Cl one
myRot PL. Tr ansf or mBy( Mat r i x3d. Rot at i on( 45 *
Page 11
Cont our Li nes. vb
Mat h. PI / 180, Vect or 3d. XAxi s, New Poi nt 3d( 0, 2, 0) ) )
Di mi nt Pt s As New Poi nt 3dCol l ect i on( )
myRot PL. I nt er sect Wi t h( myPL,
I nt er sect . Ext endBot h, i nt Pt s, I nt Pt r . Zer o, I nt Pt r . Zer o)
DebugWr i t ePt Col l ( i nt Pt s)
myPL. Di spose( )
myRot PL. Di spose( )
End Sub
<CommandMet hod( " DBText Posi t i on" ) > _
Publ i c Sub DBText Posi t i on( )
Di mcur Doc As Document =
Document Manager . Mdi Act i veDocument
Di mmyDBPoi nt As New
Dat abaseSer vi ces. DBPoi nt ( New Poi nt 3d( 2, 2, 2) )
Di mmyDBText As New Dat abaseSer vi ces. DBText
Wi t h myDBText
. Posi t i on = New Poi nt 3d( 2, 2, 2)
. Hei ght = 0. 25
. Hor i zont al Mode =
Text Hor i zont al Mode. Text Cent er
. Ver t i cal Mode =
Text Ver t i cal Mode. Text Ver t i cal Mi d
. Rot at i on = 0
. Text St r i ng = " 88"

' . Adj ust Al i gnment ( Host Appl i cat i onSer vi ces. Wor ki ngDat aba
se)
' ' Set t he al i gnment f or t he t ext
I f . Hor i zont al Mode <>
Text Hor i zont al Mode. Text Lef t Or
. Ver t i cal Mode <>
Text Ver t i cal Mode. Text Base Then
. Al i gnment Poi nt = New Poi nt 3d( 2, 2, 2)
End I f
End Wi t h
AddToModel Space( cur Doc. Dat abase, myDBPoi nt ,
myDBText )
Page 12
Cont our Li nes. vb
End Sub
<CommandMet hod( " t est Fi xText Angl e" ) > _
Publ i c Sub t est Fi xText Angl e( )
Di mor i gi nal Angl e As Doubl e
Di mf i xedAngl e As Doubl e
For i As I nt eger = 1 To 32
or i gi nal Angl e = ( i - 1) / 16 * Mat h. PI
f i xedAngl e =
Fi xText Rot at i onAngl e( or i gi nal Angl e)

Debug. Wr i t eLi ne( or i gi nal Angl e. ToSt r i ng( " F3" ) & vbTab &
f i xedAngl e. ToSt r i ng( " F3" ) )
Next
End Sub
End Cl ass
Page 13

You might also like