deejaydave Posted July 2, 2018 Posted July 2, 2018 I am trying to find out if you can use a text file (converted from a spreadsheet) to add dynamic blocks to a drawing, not just the X, Y coordinates, but the angle (not standard rotation, the dynamic one). The block I am working with reflects “Dip & Strike”. The block has only three (3) dynamic variables, Angle, Basepoint and Visibility Drop List. I want to automate adding multiple blocks without having to change the angle one at a time. Any help would be appreciated. Quote
BIGAL Posted July 3, 2018 Posted July 3, 2018 Go to the source http://WWW.lee-mac.com and get his dynamic block lisp. You could read a text file insert the block then pass all the required values to your dynamic block. If you dont know how to use lisp post a dwg and a text file. A good subject to learn about. Note also can do csv files. Quote
deejaydave Posted July 3, 2018 Author Posted July 3, 2018 Thanks for the reply BIGAL, unfortunately none of Dynamic Block lisp files will help me achieve exactly what I want. I have a feeling that bulk manipulation of dynamic blocks is not a simple task and not easily solved. Quote
BIGAL Posted July 4, 2018 Posted July 4, 2018 You can do what you want ! Look at a simple rectangle dynamic block length & width are dynamic so a text file would look like this. x y len wid 1 2 12.45 12.56 10 10 10 10 You would read the line and set the variables x,y Len & WId insert dynamic block x,y 1 1 0 then update the dynamic block with correct Length & width. You can cut the middle man out if you want and just read direct form excel, but lets crawl before we run. Post your dwg with the block. Quote
deejaydave Posted July 5, 2018 Author Posted July 5, 2018 Thanks. I have attached a drawing containing the block. I appreciate the help. deejaydave Dip Block Test.dwg Quote
BIGAL Posted July 5, 2018 Posted July 5, 2018 (edited) Try this ; dynamic block insert from csv ; by Alan H July 2018 ; thanks to Lee-mac for this defun and the dynamic block put defun (defun _csv->lst ( str / pos ) (if (setq pos (vl-string-position 44 str)) (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)))) (list str) ) ) ;The dtr function converts degrees to radians ;The rtd function converts radians to degrees (defun dtr (a) (* pi (/ a 180.0)) ) (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) (defun AH:setdyn ( / obj att fo x y ang oldattdia ) (setq oldattdia (getvar 'attdia)) (setvar "attdia" 0) (setq fo (open (getfiled "Text Export File" "" "csv" 4) "R")) (while (setq newline(read-line fo)) (setq lst (_csv->lst newline)) (setq x (atof (nth 0 lst))) (setq y (atof (nth 1 lst))) (setq ang (nth 2 lst)) (setq dynvar (nth 3 lst)) (command "insert" "DIP_STRIKE" (list x y) 1 1 0) (setq obj (vlax-ename->vla-object (entlast))) (LM:setdynpropvalue obj "Angle1" ( - 0.0 (dtr (atof ang)))) (LM:setdynpropvalue obj "Visibility1" dynvar) ) (close fo) (command "Regen") (setvar 'attdia oldattdia) (princ) ) Save this as say test.csv 100,100,45,With Arrowhead 200,5,32,With pointer -200,-200,14,ArrowHead Without Strike 300,200,90,Pointer Without Strike Edited July 7, 2018 by BIGAL Quote
deejaydave Posted July 5, 2018 Author Posted July 5, 2018 BIGAL Thanks for the code. Unfortunately it has done something to the angles, it shows 14° when it should be 346°. It seems to have reverted to AutoCAD's setup, I work on the principal of 0° = N, 180°=S etc. The code might come in handy for other blocks in the future, so a big thanks for the work. Regards deejaydave Quote
BIGAL Posted July 6, 2018 Posted July 6, 2018 We spend a lot of time doing something to try and just saying oh angles are wrong will not get you much support in future, it can be fixed, we have limited info to go on when trying to solve a problem and it may take a couple of attempts, angle in AutoCAD can be controlled. take the 4 examples and post an image of what they should be. Quote
deejaydave Posted July 6, 2018 Author Posted July 6, 2018 I was just being specific, sorry if it sounded otherwise. I have attached the test drawing from before with a few annotations (direction of rotation, degree points etc). I hope this helps. (Question. The language code used, what is it?) Thanks very much for the help. Regards deejaydave Dip Block Test.dwg Quote
BIGAL Posted July 7, 2018 Posted July 7, 2018 Hopefully fixed just removed the attribute update and inserted in a different way. Code updated. The code is written in lisp and Visual Lisp, Autocad Lisp has been around since day dot, and visual lisp was introduced years ago adding more functions. The majority here of code is lisp and a bit of VBA and some .Net which is a high level programming approach. Quote
harshad Posted July 9, 2018 Posted July 9, 2018 u have data in excel like xyz and angel of that block ?? Quote
deejaydave Posted July 9, 2018 Author Posted July 9, 2018 Hi BIGAL Thanks for the update. I am not sure if I have done something wrong (which is a possibility), but when I have loaded the lisp file I don't seem to get the option to choose a CSV file like the first iteration. I have copied the updated program text from your message, copied it to Notepad++ and saved it as DIP.LSP. Any thoughts. Many thanks deejaydave Quote
BIGAL Posted July 9, 2018 Posted July 9, 2018 I tested again copying code from here a new restart to make sure. Copy just this line only directly to the command line it should open a windows explorer style dialouge to pick the csv. (setq fo (open (getfiled "Text Export File" "" "csv" 4) "R")) then (close fo) Copy the code to notepad and resave. Quote
deejaydave Posted July 9, 2018 Author Posted July 9, 2018 I tested again copying code from here a new restart to make sure. Copy just this line only directly to the command line it should open a windows explorer style dialouge to pick the csv. (setq fo (open (getfiled "Text Export File" "" "csv" 4) "R")) then (close fo) Copy the code to notepad and resave. Am I correct in assuming that I must load the lisp file first, then enter (paste) the first bit of code here to the command line (loading csv), then enter the second bit of code. Is that correct. Quote
BIGAL Posted July 10, 2018 Posted July 10, 2018 The 1st line should just open up the select file dialouge window you said this is not working it should start with say your C:drive once you pick a csv file just paste the 2nd line it closes the file so no errors about having a file open to do stuff. You should see something like # on the command line this is saying it found the file you want to use. Quote
deejaydave Posted July 10, 2018 Author Posted July 10, 2018 Hi BIGAL I think my last message was not too clear, in which order do I do everything. Is it load lisp, enter first bit of code to load csv, then enter second bit of code to close file, or should there be another order. I ask, because whether I load the lisp before or after entering the code, nothing seems to happen. The CSV files loads (I get #), so if you could let me know which order I should be doing this I that would be great. Have a good day deejaydave Quote
BIGAL Posted July 10, 2018 Posted July 10, 2018 It sounds like your csv is not the same pattern as mine can you post a sample please. Here is a few more inserts which is what I used with your sample dwg and worked perfect, copy this to notepad and save as say test.csv in "E:\013\ALSP0903\" and try the full code again. 100,100,45,With Arrowhead 200,5,32,With pointer -200,-200,14,ArrowHead Without Strike 300,200,90,Pointer Without Strike -150,-200,142,ArrowHead Without Strike 180,-200,275,ArrowHead Without Strike 200,200,345,ArrowHead Without Strike Quote
deejaydave Posted July 10, 2018 Author Posted July 10, 2018 I have attached csv file as requested. Cheers deejaydave dipstrike.csv Quote
BIGAL Posted July 11, 2018 Posted July 11, 2018 I have no idea just copied your block to my default template dwg apploaded the lisp and opened your csv file and it all worked. Can you run it then when it crashes do F2 and copy all the command line entries to say notepad save and post file here. Quote
deejaydave Posted July 11, 2018 Author Posted July 11, 2018 Hi Thanks for getting back to me, I have attached the text file. Maybe there is a problem with my cad or my version of cad (ver. 17). Many Thanks deejaydave CAD_List.txt Quote
Recommended Posts
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.