Shablab Posted March 14, 2019 Posted March 14, 2019 I want to be able to import 5-10 different blocks that need to be placed at approximately 70 locations each. I want to achieve this by taking a CSV file I have with the following attributes: (NAME, Xcoord, Ycoord, Zcoord) and then place the 'NAME' block at the correct coordinates within the drawing. The blocks are already preloaded within the drawing itself so they can be referenced by name. Quote
rlx Posted March 14, 2019 Posted March 14, 2019 (edited) quickly written & totally untested without example dwg / csv (defun c:t1 ( / SplitStr doc spc csv fp data bn) (defun SplitStr ( s d / p ) (if (setq p (vl-string-search d s)) (cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s))) (if (and (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-block (vla-get-activelayout doc))) (setq csv (getfiled "Select csv file" "" "csv" 0) fp (open csv "r"))) (while (and (setq data (read-line fp)) (setq data (splitstr data ",") bn (car data) pnt (cdr data))) (if (tblsearch "block" bn)(vla-InsertBlock spc (vlax-3d-point (mapcar 'atof pnt)) bn 1 1 1 0)))) (princ)) Edited March 14, 2019 by rlx Quote
Shablab Posted March 14, 2019 Author Posted March 14, 2019 Seems to be 'bad argument p'. Attached is a condensed excel file as well as a drawing with the blocks inside if that helps. Book1 test.csv Test Block at coord.dwg Quote
rlx Posted March 14, 2019 Posted March 14, 2019 try now (defun c:t1 ( / SplitStr doc spc csv fp data bn) (defun SplitStr ( s d / p ) (if (setq p (vl-string-search d s)) (cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s))) (if (and (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-block (vla-get-activelayout doc))) (setq csv (getfiled "Select csv file" "" "csv" 0))(setq fp (open csv "r")) (read-line fp)) (while (and (setq data (read-line fp)) (setq data (splitstr data ",") bn (car data) pnt (cdr data))) (if (tblsearch "block" bn)(vla-InsertBlock spc (vlax-3d-point (mapcar 'atof pnt)) bn 1 1 1 0)))) (if fp (close fp)) (princ) ) 2 Quote
Shablab Posted March 15, 2019 Author Posted March 15, 2019 14 hours ago, rlx said: try now (defun c:t1 ( / SplitStr doc spc csv fp data bn) (defun SplitStr ( s d / p ) (if (setq p (vl-string-search d s)) (cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s))) (if (and (setq doc (vla-get-activedocument (vlax-get-acad-object)) spc (vla-get-block (vla-get-activelayout doc))) (setq csv (getfiled "Select csv file" "" "csv" 0))(setq fp (open csv "r")) (read-line fp)) (while (and (setq data (read-line fp)) (setq data (splitstr data ",") bn (car data) pnt (cdr data))) (if (tblsearch "block" bn)(vla-InsertBlock spc (vlax-3d-point (mapcar 'atof pnt)) bn 1 1 1 0)))) (if fp (close fp)) (princ) ) That worked beautifully! Thank you so much! Quote
rlx Posted March 15, 2019 Posted March 15, 2019 1 minute ago, Shablab said: That worked beautifully! Thank you so much! you're welcome... really was a small fix. First line in your csv has a header and without having the csv file on my first attempt I didn't account for that. After seeing the file it was simply a matter of sipping the first line 1 Quote
Fredricc Posted March 21, 2019 Posted March 21, 2019 whats the command in cad when use this lisp ? t1 gets me the option to choose csv, then after choose it nothing happens ? Quote
rlx Posted March 21, 2019 Posted March 21, 2019 are you using shablab's drawing or one of your own? Drawing must have preloaded block's (see first post , last sentence ) Quote
rlx Posted March 21, 2019 Posted March 21, 2019 2 minutes ago, Fredricc said: i trying on different drawings the point is , the csv file contains the coordinates and the blocknames of the block to be inserted. These block must be present in the drawing before you can use the lisp routine. If you have purged the drawing, all the block definitions will be gone before you can do anything so you have to use the drawing from 3rd post , and without purging the drawing. Quote
Fredricc Posted March 21, 2019 Posted March 21, 2019 ok! was not this type of lisp i was serching for here but in some way i was turned into this thread and tryed it. thx for the info! Quote
BIGAL Posted March 22, 2019 Posted March 22, 2019 A little bit more. A simple defun can be added that checks the block exists if not insert it, then delete it, the block definition stays in the dwg. But the block must be available as a seperate dwg saved in say a block library. Quote
Tomislav Posted April 11, 2019 Posted April 11, 2019 On 3/22/2019 at 1:51 AM, BIGAL said: A little bit more. A simple defun can be added that checks the block exists if not insert it, then delete it, the block definition stays in the dwg. But the block must be available as a seperate dwg saved in say a block library. can you somehow pull it out of Tool Palettes with lisp Quote
BIGAL Posted April 12, 2019 Posted April 12, 2019 (edited) No need for tool palettes, where is the block ? Is it a dwg on its own ? Then just use Insert to drag it into the current dwg you must have full path of dwg location Or is it a block in another dwg. You can use lee-mac Steal.lsp, in a lisp it can be ran with out user input to pull a block out of another dwg. ; checks for block (if (tblsearch "Block" "Holden") (princ "Holden") (progn (command "Insert" "p:\\Autodesk\\vba\\holdencar.dwg" "0,0" 1 1 0) (command "erase" "last" "") ) ; progn ) Edited April 12, 2019 by BIGAL Quote
Tomislav Posted April 12, 2019 Posted April 12, 2019 Thank you for advice Bigal, and you Rlx for lisp. Yes, I must use Lee's lisp because blocks are in a drawing, just need to change this lisp cause my block names are at the end of line and also do some lists comparing cause my names in list don't correspond to names in dwg where I'm supposed to get'em out. Quote
BIGAL Posted April 13, 2019 Posted April 13, 2019 (edited) The instruction to call a block from a dwg are in Lee's Steal.lsp you should read 1st, I have used it and it works well, just trying to remember which bit of code its in. ; cut a bit out of the code (if (not steal)(load "Stealv1-6")) (Steal <Dwg> <ItemList>) dwg obvious full pathed dwg name (Steal "C:\\My Folder\\MyDrawing.dwg" '( ("Blocks" "Block1" "Block22") ) ) Edited April 13, 2019 by BIGAL 1 Quote
Tomislav Posted April 20, 2019 Posted April 20, 2019 (edited) i need your help guys again...when passing block name as a string to the Lee's lisp i get 'Error: bad argument type: stringp KBN' where KBN contains string with block name, so how to pass it, thanx (Steal "D:\\Geodezija\\Kartografska zbirka\\1000_BLOKOVI.dwg" '(("Blocks" (kbn) ) ) ) ;_ Steal Edited April 20, 2019 by Tomislav Quote
dlanorh Posted April 20, 2019 Posted April 20, 2019 (edited) 14 minutes ago, Tomislav said: i need your help guys again...when passing block name as a string to the Lee's lisp i get 'Error: bad argument type: stringp KBN' where KBN contains string with block name, so how to pass it, thanx (Steal "D:\\Geodezija\\Kartografska zbirka\\1000_BLOKOVI.dwg" '(("Blocks" (kbn) ) ) ) ;_ Steal Format is (Steal <Drawing Filename> <Item List>) Drawing Filename (dwg) The full filename of the drawing from which items are to be imported. Item List (lst) A list of items to be imported, in the following format: ( ( <Collection 1> (<Item 1> <Item 2> ... <Item N>) ) ( <Collection 2> (<Item 1> <Item 2> ... <Item N>) ) ... ( <Collection N> (<Item 1> <Item 2> ... <Item N>) ) ) Try (Steal "D:\\Geodezija\\Kartografska zbirka\\1000_BLOKOVI.dwg" (list (list "Blocks" (list kbn))) ) ;_ Steal Edited April 20, 2019 by dlanorh 1 Quote
Tomislav Posted April 20, 2019 Posted April 20, 2019 (edited) well that just worked, thank you...i still don't quite get it why list,list,list instead of '(("Blocks" (kbn)) but must work on it Edited April 20, 2019 by Tomislav Quote
dlanorh Posted April 20, 2019 Posted April 20, 2019 3 hours ago, Tomislav said: well that just worked, thank you...i still don't quite get it why list,list,list instead of '(("Blocks" (kbn)) but must work on it The first quote '( means everything is literal, and it isn't as you have an evaluation (kbn = string value). This means that you must evaluate everything into the item to be evaluated. Putting brackets round items doesn't make a list (setq a (10 20 30)) => ;error: bad function: 10. This is looking for a function called 10 (defun 10 ( a b / )......) with two parameters to pass in (setq a '(10 20 30)) => (10 20 30) (type a) => LIST but (setq b 20) (setq a '(10 b 30)) => (10 B 30) (type a) => LIST ; ' means literal b is not evaluated (setq a (list 10 b 30)) => (10 20 30) (type a) => LIST ;Now b is evaluated 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.