Jump to content

Recommended Posts

Posted

ANGLE LEG_SAMPLE.xlsx

 

I am sorry if got the category messed up, but could not find a category for my question so I will pose it here.

Attached is the excel Polar coordinate I am trying to generate in Autocad. I used excel VBA to give me a polar coordinate based on the variables I entered. Is it possible for someone to tell me how I should write an Excel VBA to upon pressing a pre-defined button in excel (say: generate drawing) could open an Autocad file, get the data from this sample excel file and draw the lines.

I was unsuccessful in LISP to do this, because I do not know much about LISP, the reason why I am involving excel in all these. i am successful in saving the coordinates as blah.scr and then go to autocad and enter script to then find the file and everything is good - but I am trying to reduce the number of steps by inserting a button on excel to do all this for me.

the snapshot below is the userform I created in excel to give me the data in the excel file attached.

image.thumb.png.7c662754bab57909b67b4c75a349b21a.png

image.png

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

  • Sambuddy

    23

  • rlx

    20

  • lrm

    9

  • BIGAL

    7

Top Posters In This Topic

Posted Images

Posted

have no experience with vba->autocad but these links look interesting

 

from bricsys forum

 

from myenginneringsworld.net

 

I know one of my colleagues has a routine which generates directly from excel , using send vba command to autocad , electrical terminal connection diagrams which he still uses. But with the turnaround from 2015 and the one going on right now he created a data base in acces , converted it to excel for me where I picked it up to generate many thousands of loops. Maybe there are more experienced on this forum who are able and willing to share or lease some of their braincells?

Posted

It is not clear to me what you are asking.  You posted the .xlsx file and not the file with the VBA code .xlsm. 

 

1. Is your program  creating a list of AutoCAD commands to create a polyline and placing those commands in column A

or 

2. Does it directly create a .scr script file.

 

You state that "...I am trying to reduce the number of steps by inserting a button on excel to do all this for me..."  What exactly is "all of this?"  Should the Excel VBA code identify a specific drawing then open it and then run the .scr file?  If so, how is the appropriate file identified. Should that be included on the form?

 

Posted

1st 

 

Simplest way is make a command sequence in a column in excel, use the concatenate command, so get x,y then just copy and paste to command line, =concatenate(b12,",",c12) will give x,y

 

This is end result in a column can use VBA macro to work out the x,y points as it supports cos sin for values just enter a starting point X & Y or else use 0 0 then move result.

 

Pline

x,y

x,y

x,y

…..

c

 

 

Posted

Good morning Irm,

I guess I sometimes even confuse myself! I did write a vba code (as I am not at all familiar with LISP) in excel and found a way for excel to give me Polar coordinates (excel file attached in earlier post). what i was asking is there is a way to either:

1) through vba coding: I could prompt autocad to draw the pline or,

2) a Lisp to execute the excel as either script or txt. Please note that my exported file will be in blah.scr for this example. I could simply run script command and then select the file directory and select the file but if there a way to automate this process I would certainly appreciate it.

 

No I did not attach the file with the vba code because that is not what my question about, since I can ask excel to export a blah.scr for me.

 

Thanksblah.scr

 

Posted

I am still confused.  I understand that your Excel VBA program creates a script file, e.g., blah.scr. 

 

Is your question that you do not want to go to AutoCAD and type:

script blah [Enter]

 

but want to execute a lisp program that has the path and script filename built in so that you do get prompted for the directory and filename?  Can it be assumed that the directory and script filename will always be the same?

 

 

 

Posted

Good morning lrm,

 

You are correct. The file name never changes and it is always (say: blah.scr), but I would like NOT to choose a directory and select file. Because blah.scr always end up on my desktop, is it possible for LISP to search and find the desktop and execute - and in the event of not finding it comes up with the message: Blah.scr does not exist. 

 

And since I would let others use it on different computers, I am not sure how you would be able to address the desktop for different users. Example mine is: C:\Users\sambuddy\Desktop\blah.scr. How could you make it so the lisp changes the user name from sambuddy to others? the key element is that the excel file always shoots out blah.scr on any user desktop.

 

I hope I am not frustrating you with my wanky questions! I sounds much better in my head by writing it down is whole other mess!

 

Thanks

Posted

After much trials, the best directory to save the blah.scr is going to be "C:\Temp". That way I would not require to delete the file after creation or worry about the different users.

 

But the rest is still hanging and require your help lrm.

 

Thanks

Posted

Create a new command in the CUI place a macro to run your script, give it an icon or command name.

^C^Cscript;"C:/Users/sambuddy/Desktop/blah.scr";

In the CUI drag the new command onto a ribbon panel (or create your own) or the menu or a toolbar. Now all you need do is click the ribbon item and the script will run. At least thats how I do it, just change the macro to suit each user.

Posted

@steven-g makes a good suggestion.

 

If you want a vlisp function you can add to your library something like the following will work (with the path and filename adjusted for your particular case).  Be sure to use double \\ as noted. 

I think having the script file in na fixed location (e.g., c:temp or) is a good idea if that will work for you.

(defun C:runblah ()
(if (findfile "c:\\Users\\SamBuddy\\Desktop\\blah.scr")
  (command "_script" "c:\\Users\\SamBuddy\\Desktop\\blah.scr")
)					; end if
(princ "\nDone")
(princ)
)

 

Posted

You see something as simple as that and I could not figure out for the life of me. 

 

Thank you very much Irm.

Posted

Hey Irm,

 

If I were to add a second command (sub command), can I just add it on the same LISP? Could you also let me know how to embed Array/"select object"/Polar/"-250,170"/Item/3/enter,

where "-250,170" is the center of polar array and "3" is the number of items to be arrayed?

Oh and, is there a way to select the object automatically (object based on Blah.scr) for the array?

(defun C:runblah ()
(if (findfile "c:\\Users\\SamBuddy\\Desktop\\blah.scr")
  (command "_script" "c:\\Users\\SamBuddy\\Desktop\\blah.scr")
  (command "_script" "c:\\Users\\SamBuddy\\Desktop\\blah2.scr")
)					; end if
(princ "\nDone")
(princ)
)
Posted

YOu could combine both tasks into one script that would look like this:

 

pline
0,0
@30<195
@72<180
@6.35<90
@71.16400664032<0
@22.81400664032<15
@22.81400664032<105
@71.16400664032<120
@6.35<30
@72<300
close
array
last

po
-250,170
3
360
Y

 

Posted

Thanks for that tip. I will try to use it next time.

 

But on the script itself: how do I make the command cancel after executing itself, example pline?

image.png.3ae53a696532d3dff7d89c603d34fefc.png

 

Now that I added 3 pline commands under one script, it seems to give me a messed up drawing with the LISP, but when I paste it directly onto the commandline everything seems fine. Am I doing something wrong here?

 

Could you please help?

 

when I run the LISP, it gives me this: 

Specify start point: pline

Invalid point.

 

This is what I have on the blah.scr:

 

pline
0,0
@30<195
@97<180
@7.9375<90
@95.9550083004<0
@21.0175083004<15
@21.0175083004<105
@95.9550083004<120
@7.9375<30
@97<300
close

pline
-933.955549577344,0
@30<75
@97<60
@7.9375<330
@95.9550083004<240
@21.0175083004<255
@21.0175083004<345
@95.9550083004<0
@7.9375<270
@97<180
close

pline
-466.977774788672,808.829231939437
@30<315
@97<300
@7.9375<210
@95.9550083004<120
@21.0175083004<135
@21.0175083004<225
@95.9550083004<240
@7.9375<150
@97<60
close
close

 

Posted

I just lost power to my house due to a storm so I am unable to test your script.

Why do you have two "close" statements at the end?

The second and third pline statements may not be needed.

I will look at this later when I get power back.

Posted

when I paste your script code  in notepad after the first close it has an empty line between close and pline. In a sript a scape or en empty line can mean enter and an enter can also mean repeat. So this empty line makes the poline command start again an the next line will be the first parameter. In this case the word pline. So check your script file for unwanted spaces / tabs etc. Make sure each line end has no extra characters. You can't always see this but using ctrl-A to select everything could give a first indication.

 

🛏️  😴

Posted (edited)

Everybody has avoided the obvious VBA excel can tell Autocad what to do. Same Autocad can tell Excel what to do.

 

Ok look at what your doing in excel if it uses VBA then look at VBA in Autocad run from there. Type VBAMAN as a start you could copy and paste code between Autocad and excel as a starting point export form import form.

Edited by BIGAL
Posted

Most of us are on this part of the forum because we want to play with lisp. VBA has its on forum on this site. VBA is no longer automatically installed with AutoCAD anymore since , what, ten years ago? Also xlsm files are blocked here at my work (of course). But I tried the example at home from my second link I posted in my first reaction on this thread and it really works , add the macro to your spread sheet and the special commands tab or download the example workbook and you can there put all the commands so you even don't need a script anymore. I'm not sure but don don't think I even have installed the vbaman in AutoCAD at home. If OP feels more comfortable with using excel , to me looks like a good option too..

 

Posted

rlx I agree use excel don't need vba even, just everyday excel cell stuff if you make the pline script as a column can copy and paste to Autocad command line. That's why I said use concatenate to make the x,y. you can work out all the co-ordinates using sin/cos.

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...