Wellington Posted May 19, 2020 Share Posted May 19, 2020 (edited) Hey guys! How's going? Can anyone help me? Look: i need to place a lot of blocks in an extensive polyline but the blocks need to have a specific distance from the polyline beginning - and this distance will not be equal to each block. So, i thought in create a list (excel or csv file) and specify each block name and distance to the lisp read the archive and place the block at correct point. Did you get it? PS: remember that the blocks will not have the same interval distance. This is an example for the list layout. And the result is something like this: I hope you guys could understand and help me! - sorry for my english - Thanks! Much love from Brazil Wellington Moura Edited May 19, 2020 by Wellington Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 20, 2020 Share Posted May 20, 2020 Its two Vlisp command to do the task 1st is (vlax-curve-getpointatdist obj dist) 2nd is (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pt)) In the case of the 2nd its about getting the angle of the pline at a point, so you block would be inserted correctly. Do you know how to write lisp ? The task is not hard. Post sample data a dwg and csv or xls. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted May 20, 2020 Share Posted May 20, 2020 8 hours ago, Wellington said: Hey guys! How's going? Can anyone help me? Look: i need to place a lot of blocks in an extensive polyline but the blocks need to have a specific distance from the polyline beginning - and this distance will not be equal to each block. So, i thought in create a list (excel or csv file) and specify each block name and distance to the lisp read the archive and place the block at correct point. Did you get it? PS: remember that the blocks will not have the same interval distance. This is an example for the list layout. And the result is something like this: I hope you guys could understand and help me! - sorry for my english - Thanks! Much love from Brazil Wellington Moura The example "excel" doesn't match the example picture! How is BLOCK 2 between BLOCK1 and BLOCK3? Does BLOCK1 repeat every 100 units? Does each BLOCK repeat the said distance until the end of the polyline? This is very easy to achieve if all the rules are known. Post an example "*.csv" and an example drawing (saved as AutoCAD2010 or earlier) with the real blocks to be used, layers for the blocks etc. Quote Link to comment Share on other sites More sharing options...
Wellington Posted May 20, 2020 Author Share Posted May 20, 2020 12 hours ago, dlanorh said: The example "excel" doesn't match the example picture! How is BLOCK 2 between BLOCK1 and BLOCK3? Does BLOCK1 repeat every 100 units? Does each BLOCK repeat the said distance until the end of the polyline? This is very easy to achieve if all the rules are known. Post an example "*.csv" and an example drawing (saved as AutoCAD2010 or earlier) with the real blocks to be used, layers for the blocks etc. The same block can appear a lot of time in differents distances along the polyline. There's a example of blocks, polyline and list to use. EXAMPLE-CSV.csv EXAMPLE-BLOCKS.dwg Quote Link to comment Share on other sites More sharing options...
Wellington Posted May 20, 2020 Author Share Posted May 20, 2020 19 hours ago, BIGAL said: Its two Vlisp command to do the task 1st is (vlax-curve-getpointatdist obj dist) 2nd is (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pt)) In the case of the 2nd its about getting the angle of the pline at a point, so you block would be inserted correctly. Do you know how to write lisp ? The task is not hard. Post sample data a dwg and csv or xls. Sorry but i dont know how to write lisp but i got the examples here. EXAMPLE-BLOCKS.dwg EXAMPLE-CSV.csv Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 22, 2020 Share Posted May 22, 2020 (edited) Try this a bit rough but should work note does not check which way pline is drawn. Can be added. hard coded for testing change to use findfile for the csv. ; Take a csv file of blk details and make in Cad ; By Alan H May 2020 ; thanks to Lee-mac for the csv defun ; www.lee-mac.com ; 44 is comma ; 59 is semicolon (defun _csv->lst (str del / pos ) (if (setq pos (vl-string-position del str)) (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)))) (list str) ) ) ; program starts here hardcoded for testing ; 1st line is heading so just read (defun c:csvblk ( / newlst x obj pt1) (setq fname (open "D:\\acadtemp\\EXAMPLE-csv.csv" "r")) (setq newline (read-line fname)) (while (setq newline (read-line fname)) (princ newline) (setq newlst (cons ( _csv->lst newline (ascii ";")) newlst)) ) (close fname) (setq obj (vlax-ename->vla-object (car (entsel "Pick pline object near start end")))) (repeat (setq x (length newlst)) (setq pair (nth (setq x (- x 1)) newlst)) (setq pt1 (vlax-curve-getpointatdist obj (atof(cadr pair)))) (command "-insert" (car pair) pt1 1 1 0) ) ) (c:csvblk) Edited May 22, 2020 by BIGAL Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted May 23, 2020 Share Posted May 23, 2020 (defun c:blkdis (/ *error* acadobj activeundo adoc bl blks dir ent i ln lst msp num op pl pm ps sep) (defun *error* ( msg ) (if op (close op)) (vla-EndUndoMark adoc) (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*exit*")) (princ (strcat "Error: " msg)) ) ) (setq acadobj (vlax-get-acad-object) adoc (vla-get-ActiveDocument acadobj) msp (vla-get-ModelSpace adoc) activeundo nil) (if (= 0 (logand 8 (getvar "UNDOCTL"))) (vla-StartUndoMark adoc) (setq activeundo T)) (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (","))) (if (and (setq dir (getfiled "Select CSV" "" "csv" 0)) (setq op (open dir "r")) (setq pl (ssget '((0 . "LWPOLYLINE,POLYLINE,ARC,ELLIPSE,CIRCLE,SPLINE")))) ) (progn (while (setq ln (read-line op)) (setq lst (cons (JH:str->lst ln sep) lst)) ) (close op) (setq lst (reverse lst) ps (vl-position "DISTANCE" (mapcar 'strcase (car lst))) bl (vl-position "BLOCK" (mapcar 'strcase (car lst))) blks (vl-remove-if-not '(lambda (x) (tblsearch "block" (car x))) (cdr lst)) blks (mapcar '(lambda (x) (mapcar '(lambda (y) (if (and (null (vl-catch-all-error-p (setq num (vl-catch-all-apply 'read (list y) ) ) ) ) (numberp num) ) num y ) ) x ) ) blks ) ) (repeat (setq i (sslength pl)) (setq ent (ssname pl (setq i (1- i)))) (foreach x blks (if (setq pm (vlax-curve-getParamAtDist ent (nth ps x))) (entmake (list '(0 . "INSERT") '(100 . "AcDbEntity") '(100 . "AcDbBlockReference") (cons 10 (vlax-curve-getPointAtParam ent pm)) (cons 2 (nth bl x)) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0) (cons 50 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv ent pm))) ) ) ) ) ) ) ) (if activeundo nil (vla-EndUndoMark adoc)) (princ) ) ;; JH:str->lst --> Jonathan Handojo ;; Seperates a string into a list using a specified delimiter ;; str - full string to parse ;; del - string representing the delimeter (defun JH:str->lst (str del / l rtn src) (setq l (1+ (strlen del))) (while (setq src (vl-string-search del str)) (setq rtn (cons (substr str 1 src) rtn) str (substr str (+ src l)) ) ) (reverse (cons str rtn)) ) Quote Link to comment Share on other sites More sharing options...
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.