Excel Drawing in AutoCAD VBA code upgrade from 2012 Library Type to Current

Excel Drawing in AutoCAD VBA code upgrade from 2012 Library Type to Current

ksflagg
Observer Observer
807 Views
3 Replies
Message 1 of 4

Excel Drawing in AutoCAD VBA code upgrade from 2012 Library Type to Current

ksflagg
Observer
Observer

Hello,
I have engineering design worksheet in excel.  I wrote Excel VBA code that converts and pushes the design data from Excel into AutoCAD as a completed drawing.
The worksheet was functional with Excel in 2012-16 and using the Auto 2012 Library Type, with AutoCAD 2012.

I am now running excel on office 365 and AutoCAD 2020.
I plan to upgrade the code to work with my current versions.

I am preemptively requesting any resources or advice on making the changes before tinkering.
Thank you! 

0 Likes
808 Views
3 Replies
Replies (3)
Message 2 of 4

grobnik
Collaborator
Collaborator

Hi @ksflagg shall be better if you share the code and perhaps a drawing could be better.

In some cases shall be enough to select updated reference libray in excel vba project.

0 Likes
Message 3 of 4

ksflagg
Observer
Observer

Here is a sample code section that uses all required commands. 

It pulls the x,y coordinates from a table in excel.

I use, acadDoc.SendCommand, acadDoc.Layers.Add(), acadPol, acadDoc.ModelSpace.AddLinghtWeightPolyline().

 

Curious if there are new ways of sending this type of input from Excel or can I just update the references and correct any syntax that might have updated.

 

 

'-----------------------
'---Draw Lines----------
'-----------------------
'----CREATE LAYER-------
Set acadL = acadDoc.Layers.Add("LINES")
acadDoc.SendCommand ("-layer" & vbCr & "set" & vbCr & "LINES" & vbCr & "color" & vbCr & "111" & vbCr & "" & vbCr & "" & vbCr)
'--Run a loop to collect line coordinates--
j = 0
For i = 1 To countX
LineCoordinates(j) = ActiveSheet.Cells(Ra - 1 + i, Ca + 1)
j = j + 1
x = ActiveSheet.Cells(Ra - 1 + i, Ca + 2) * s
LineCoordinates(j) = x + p
j = j + 1
Next i
'--Draw the polyline in model space--
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(LineCoordinates)
'--Leave the polyline open--
acadPol.Closed = False
acadPol.Update

 

 

0 Likes
Message 4 of 4

grobnik
Collaborator
Collaborator

@ksflagg 

Could you try with below code for changing layer color, supposing acadDoc referred to current drawing not to application,

The other command seems simple, so I guess you have to update reference project library,

 

Dim Lay As AcadLayer
    Set Lay = acadDoc.Layers("LINES")
    Lay.color = 111

 

 

0 Likes