Jump to content

Recommended Posts

Posted

Hi,

 

Can anyone direct me to a good example of drawing multilines using vba?

 

I looked in the help file but doesnt seem to be a lot of info on it?

 

Cheers,

 

Col

Posted

You seed your points as XYZ sets, so the number of points for the 'main' part of the line will be an array of sets of 3: the points on your main line will be indexes 0,1,2 for the first point, indexes 3,4,5 for the second point, indexes 6,7,8 for the third point. etc, etc.

 

The Justification is the side to offset by. acTop & acBottom are which "side" to offset your "main" line by: acZero basically offsets both lines from your imaginary line running down the middle of your points.

 

MLineScale controls the offset amount.

 

The sample code provided in the help, is not much help.

Take the sample code, erase all the points except those from index

0-8, and make them the following values:

0=0. 1=0. 2=0.

3=0. 4=-10. 5=0.

6=10. 7=-10. 8=0

 

This will basically make an "L" shape, unlike the overlapping crap that the sample source gives you.

 

Then play with the Justification and MLinScale properties; you should get the hang of it then.

Posted

Hi, Col

Not sure about what you mean but

hope it will helps, just pick points on screen

 

Public Sub DrawMLineDynamicaly()
' partially borrowed from Tony Tanzillo's 'Getpoint' function
Dim pickPt As Variant
Dim mlCoords() As Double
Dim i As Integer
Dim oMline As AcadMLine

i = 0
On Error Resume Next
pickPt = ThisDrawing.Utility.GetPoint(, vbCr & "First point: ")
If Err = 0 Then
   ReDim mlCoords(2)
   mlCoords(i) = pickPt(0): mlCoords(i + 1) = pickPt(1): mlCoords(i + 2) = 0#
   Do Until Err.Number <> 0
       i = i + 3
       pickPt = ThisDrawing.Utility.GetPoint(pickPt, vbCr & "Pick next point or press Enter to stop: ")
       ReDim Preserve mlCoords(UBound(mlCoords) + 3)
       mlCoords(i) = pickPt(0): mlCoords(i + 1) = pickPt(1): mlCoords(i + 2) = 0#
       If oMline Is Nothing Then
           Set oMline = ThisDrawing.ModelSpace.AddMLine(mlCoords)
           oMline.Update
       Else
           oMline.Coordinates = mlCoords
           oMline.Update
       End If
   Loop

End If

End Sub

 

~'J'~

Posted

Fixo,

 

Thank you for that. What I am trying to create is a version of the code you posted but to allow the user to type in size,s width, height and qty of bays and to end product to be curtain walling screen.

 

Thank you for thehelp.

 

Cheers,

 

col

Posted

Rocheey,

Thank you for the explanation. You didn’t mention mlinestyle? I see from help that it is read only?

 

I tried

MyObjMLine.stylename = “MLineStyleName”

 

And it returned an error. Does this mean it can not be changed with vba and you have to do it manually?

Cheers,

 

Col

Posted
Rocheey,

Thank you for the explanation. You didn’t mention mlinestyle? I see from help that it is read only?

 

I tried

MyObjMLine.stylename = “MLineStyleName”

 

And it returned an error. Does this mean it can not be changed with vba and you have to do it manually?

Cheers,

 

Col

Col, please, take a look at the Help always:

 

From Help

StyleName

For the MLine object, this property is read-only

 

To set desired MlineStyle use:

ThisDrawing.SetVariable "CMLSTYLE", "MyStyleName" '<--style name

the same things with scale and justification:

ThisDrawing.SetVariable "CMLSCALE", 10.0 <--scale
ThisDrawing.SetVariable "CMLJUST", 1 '<--justification to middle

 

After that you can draw multiline with desired parameters

 

~'J'~

Posted
Fixo,

 

Thank you for that. What I am trying to create is a version of the code you posted but to allow the user to type in size,s width, height and qty of bays and to end product to be curtain walling screen.

 

Thank you for thehelp.

 

Cheers,

 

col

Col, sorry, I don't understand what you mean

Please, upload here the small picture or the sample

drawing to enlight me with it

 

~'J'~

Posted

Thank you for the set variable, it worked fine.

 

I doo look at help but some times find it hard to get what i am looking for. Thank you for the help.

I will post a sample drawing/ jpeg later today.

 

I would appreciate any pointers. i think i can use the code you posted but jsut have the points calculated from input added by the user.

 

will post the jpeg later.

 

thank you for the help.

 

cheers,

 

col

Posted

Fixo,

 

jpeg attached. it is a very simple example, the amount of columns/ rows could 10 or 100, for eg.

 

Im sure i can use you example, i just need to work out how to accept input from the command line and then work out the calculation required.

 

cheers,

 

col

example jpeg.jpg

Posted

Here is an example what you looking for

I don't like to use command line for entering

values, so I used InputBox instead:

 

Sub DrawFrameTest()

Dim strMStyle As String
Dim structWid As Double
Dim frameWid As Double
Dim structHgt As Double
Dim frameHgt As Double
Dim beamWid As Double
Dim hnum As Integer
Dim vnum As Integer
Dim varpt As Variant
Dim hstep As Double
Dim vstep As Double
Dim pts(5) As Double
Dim movept(2) As Double
Dim oMLine As AcadMLine
Dim cMline As AcadMLine
Dim cnt As Integer
strMStyle = "STANDARD"
structWid = CDbl(InputBox("Structural Opening Width:", "Structural Width", "7733.0"))
frameWid = CDbl(InputBox("Frame Width:", "Frame Width", "7712.0"))
structHgt = CDbl(InputBox("Structural Opening Height:", "Structural Height", "2986.0"))
frameHgt = CDbl(InputBox("Frame Height:", "Frame Height", "2966.0"))
beamWid = CDbl(InputBox("Beam Width:", "Beam Width", "50.0"))
ThisDrawing.SetVariable "CMLJUST", 1
ThisDrawing.SetVariable "CMLSTYLE", strMStyle

hnum = CInt(InputBox("Number Of Horizontal Beams:", "Horizontal Beams", "4"))
vnum = CInt(InputBox("Number Of Vertical Beams:", "Vertical Beams", "4"))

varpt = ThisDrawing.Utility.GetPoint(, vbCr & "Pick lower left point of construction:")

ThisDrawing.Regen acActiveViewport
'calculations
hstep = (frameWid - (beamWid * vnum)) / (vnum - 1)
vstep = (frameHgt - (beamWid * hnum)) / (hnum - 1)
pts(0) = varpt(0) - beamWid: pts(1) = varpt(1) + beamWid / 2: pts(2) = 0#
pts(3) = pts(0) + frameWid: pts(4) = pts(1): pts(5) = 0#
'horizontal beams
Set oMLine = ThisDrawing.ModelSpace.AddMLine(pts)
oMLine.MLineScale = beamWid
oMLine.Update
Do While cnt < hnum - 1
Set cMline = oMLine.Copy
cMline.MLineScale = beamWid
cMline.Update
movept(0) = varpt(0)
movept(1) = varpt(1) + (cnt + 1) * (vstep + beamWid)
movept(2) = 0#
cMline.Move varpt, movept
cnt = cnt + 1
Loop
'vertical beams
cnt = 0
pts(0) = varpt(0) - beamWid / 2: pts(1) = varpt(1): pts(2) = 0#
pts(3) = pts(0): pts(4) = pts(1) + frameHgt: pts(5) = 0#

Set oMLine = ThisDrawing.ModelSpace.AddMLine(pts)
oMLine.MLineScale = beamWid
oMLine.Update
hstep = (frameWid - (beamWid * vnum)) / (vnum - 1)
vstep = (frameHgt - (beamWid * hnum)) / (hnum - 1)
Do While cnt < vnum - 1
Set cMline = oMLine.Copy
cMline.MLineScale = beamWid
cMline.Update
movept(0) = varpt(0) + (cnt + 1) * (hstep + beamWid)
movept(1) = varpt(1)
movept(2) = 0#
cMline.Move varpt, movept
cnt = cnt + 1
Loop

End Sub

 

~'J'~

Posted

Fixo,

 

thank you. it worked really well.

 

I will try to develop it further.

 

Many thanks,

 

Col

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...