chelsea1307 Posted May 28, 2009 Share Posted May 28, 2009 still learning lisp, Would it be possible to have a lisp ask for user to select two blocks (in specific order) then to select a pline then select a mtext and have the lisp put the attribute info from the blocks the length of the pline and the mtext in a block that i can then extract? also would it be possible to have it ask the question -coil?- if y then select mtext last of n then dont select mtext last. Lee wrote a great one that puts the length in mtext and that inserts my nodes (the blocks with the needed attribute). any help would be great. NODE-Model.pdf Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 I don't quite follow - do you want the length and MTEXT contents to be put into the same block? - A different block to the NODE blocks? Also, what is to be done to the NODE blocks? Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 just pulling the number from the node blocks the new block would read node# node# length mtext Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 What is the name of this new block? Or would the LISP create that as well? Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 I can create a block for it or the lisp can create one whichever is easier Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 I can create a block for it or the lisp can create one whichever is easier It would be easier if the block was already created and was in either the Search Path (easiest) or in a known location. If the LISP had to create it, this requires a lot more coding and if very tedious tbh. Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 I can do that. It will be called node.dwg Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 the origional node block (pnode) will remain where its at just pulling the number to put into the new block node. Im doing hydronic calculations and i have to mesure the distance between nodes then enter the node numbers and the distance and in cases where there is a coil the gpm (mtext) into another program. if i can get all the information into a block i can extract it to xcell and have it all on one sheet thats easy to read instead of moving around the dwg the whole time. am i making any sense yet? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 the origional node block (pnode) will remain where its at just pulling the number to put into the new block node. Im doing hydronic calculations and i have to mesure the distance between nodes then enter the node numbers and the distance and in cases where there is a coil the gpm (mtext) into another program. if i can get all the information into a block i can extract it to xcell and have it all on one sheet thats easy to read instead of moving around the dwg the whole time. am i making any sense yet? Yes, that makes sense - I will see what I can do, when I have some time Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 ok. I attached a picture to help explain Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 Ahh, one more thing, what are the TAGs for the attributes to be filled in? Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 node1 node2 length coil try it now NODE.dwg Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 Do you have that in 2004 format please? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 28, 2009 Share Posted May 28, 2009 Something like this possibly? (defun c:NdUpd (/ doc spc nd1 nd2 pl mtxt pt ndlst blk) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (or (tblsearch "BLOCK" "NODE") (findfile "NODE.dwg")) (if (and (setq nd1 (car (entsel "\nSelect Node 1: "))) (eq "INSERT" (cdadr (entget nd1))) (eq "PNODE" (cdr (assoc 2 (entget nd1))))) (if (and (setq nd2 (car (entsel "\nSelect Node 2: "))) (eq "INSERT" (cdadr (entget nd2))) (eq "PNODE" (cdr (assoc 2 (entget nd2))))) (if (and (setq pl (car (entsel "\nSelect Line Object: "))) (member (cdadr (entget pl)) '("LWPOLYLINE" "POLYLINE" "LINE"))) (if (and (setq mtxt (car (entsel "\nSelect MTEXT: "))) (wcmatch (cdadr (entget mtxt)) "*TEXT")) (if (setq pt (getpoint "\nSelect Point for Block: ")) (progn (setq ndlst (mapcar (function (lambda (x) (cdr (assoc 1 (entget (entnext x)))))) (list nd1 nd2))) (setq blk (vla-insertblock spc (vlax-3D-point (trans pt 1 0)) "NODE.dwg" 1. 1. 1. 0.)) (foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes blk))) (cond ((eq "NODE1" (vla-get-TagString att)) (vla-put-TextString att (car ndlst))) ((eq "NODE2" (vla-get-TagString att)) (vla-put-TextString att (cadr ndlst))) ((eq "LENGTH" (vla-get-TagString att)) (vla-put-TextString att (rtos (vla-get-Length (vlax-ename->vla-object pl))))) ((eq "COIL" (vla-get-TagString att)) (vla-put-TextString att (cdr (assoc 1 (entget mtxt)))))))) (princ "\n<!> No Point Selected <!>")) (princ "\n<!> Incorrect MTEXT Selection <!>")) (princ "\n<!> Incorrect LINE Object Selection <!>")) (princ "\n<!> Incorrect Selection of NODE 2 <!>")) (princ "\n<!> Incorrect Selection of NODE 1 <!>")) (princ "\n<!> NODE Block not Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 It works great for the ones that have coils and mtext, but it errors out if i dont have mtext, is there a way to make the mtext selection optional? if you click it it includes it, if you dont it skips it and continues? or something Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 28, 2009 Author Share Posted May 28, 2009 The code you gave me works great except for instances where i dont have mtext. I tried to take it out and gave it a new block (one without the coil spot) but it says too few arguments, anyone see where i went wrong? (defun c:NdUpd2 (/ doc spc nd1 nd2 pl mtxt pt ndlst blk) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (or (tblsearch "BLOCK" "NODE2") (findfile "Node2.dwg")) (if (and (setq nd1 (car (entsel "\nSelect Node 1: "))) (eq "INSERT" (cdadr (entget nd1))) (eq "PNODE" (cdr (assoc 2 (entget nd1))))) (if (and (setq nd2 (car (entsel "\nSelect Node 2: "))) (eq "INSERT" (cdadr (entget nd2))) (eq "PNODE" (cdr (assoc 2 (entget nd2))))) (if (and (setq pl (car (entsel "\nSelect Line Object: "))) (member (cdadr (entget pl)) '("LWPOLYLINE" "POLYLINE" "LINE"))) (if (setq pt (getpoint "\nSelect Point for Block: ")) (progn (setq ndlst (mapcar (function (lambda (x) (cdr (assoc 1 (entget (entnext x)))))) (list nd1 nd2))) (setq blk (vla-insertblock spc (vlax-3D-point (trans pt 1 0)) "Node2.dwg" 1. 1. 1. 0.)) (foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes blk))) (cond ((eq "NODE1" (vla-get-TagString att)) (vla-put-TextString att (car ndlst))) ((eq "NODE2" (vla-get-TagString att)) (vla-put-TextString att (cadr ndlst))) ((eq "LENGTH" (vla-get-TagString att)) (vla-put-TextString att (rtos (vla-get-Length)))))))) (princ "\n<!> No Point Selected <!>")) (princ "\n<!> Incorrect LINE Object Selection <!>")) (princ "\n<!> Incorrect Selection of NODE 2 <!>")) (princ "\n<!> Incorrect Selection of NODE 1 <!>")) (princ "\n<!> NODE Block not Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 29, 2009 Share Posted May 29, 2009 This should provide the option of no MTEXT... (defun c:NdUpd (/ doc spc nd1 nd2 pl mtxt pt ndlst blk) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (or (tblsearch "BLOCK" "NODE") (findfile "NODE.dwg")) (if (and (setq nd1 (car (entsel "\nSelect Node 1: "))) (eq "INSERT" (cdadr (entget nd1))) (eq "PNODE" (strcase (cdr (assoc 2 (entget nd1)))))) (if (and (setq nd2 (car (entsel "\nSelect Node 2: "))) (eq "INSERT" (cdadr (entget nd2))) (eq "PNODE" (strcase (cdr (assoc 2 (entget nd2)))))) (if (and (setq pl (car (entsel "\nSelect Line Object: "))) (member (cdadr (entget pl)) '("LWPOLYLINE" "POLYLINE" "LINE"))) (if (setq pt (getpoint "\nSelect Point for Block: ")) (progn (and (setq mtxt (car (entsel "\nSelect MTEXT: "))) (wcmatch (cdadr (entget mtxt)) "*TEXT")) (setq ndlst (mapcar (function (lambda (x) (cdr (assoc 1 (entget (entnext x)))))) (list nd1 nd2))) (setq blk (vla-insertblock spc (vlax-3D-point (trans pt 1 0)) "NODE.dwg" 1. 1. 1. 0.)) (foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes blk))) (cond ((eq "NODE1" (vla-get-TagString att)) (vla-put-TextString att (car ndlst))) ((eq "NODE2" (vla-get-TagString att)) (vla-put-TextString att (cadr ndlst))) ((eq "LENGTH" (vla-get-TagString att)) (vla-put-TextString att (rtos (vla-get-Length (vlax-ename->vla-object pl))))) ((eq "COIL" (vla-get-TagString att)) (vla-put-TextString att (if mtxt (cdr (assoc 1 (entget mtxt))) "")))))) (princ "\n<!> No Point Selected <!>")) (princ "\n<!> Incorrect LINE Object Selection <!>")) (princ "\n<!> Incorrect Selection of NODE 2 <!>")) (princ "\n<!> Incorrect Selection of NODE 1 <!>")) (princ "\n<!> NODE Block not Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 29, 2009 Author Share Posted May 29, 2009 That works great. Would it be hard to add a spot to ask for turns and take a numerical insert from 0 up? I can add it to the block with the tag turns Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 29, 2009 Share Posted May 29, 2009 Not too difficult (defun c:NdUpd (/ doc spc nd1 nd2 pl mtxt pt ndlst blk turns) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (or (tblsearch "BLOCK" "NODE") (findfile "NODE.dwg")) (if (and (setq nd1 (car (entsel "\nSelect Node 1: "))) (eq "INSERT" (cdadr (entget nd1))) (eq "PNODE" (strcase (cdr (assoc 2 (entget nd1)))))) (if (and (setq nd2 (car (entsel "\nSelect Node 2: "))) (eq "INSERT" (cdadr (entget nd2))) (eq "PNODE" (strcase (cdr (assoc 2 (entget nd2)))))) (if (and (setq pl (car (entsel "\nSelect Line Object: "))) (member (cdadr (entget pl)) '("LWPOLYLINE" "POLYLINE" "LINE"))) (if (setq pt (getpoint "\nSelect Point for Block: ")) (progn (and (setq mtxt (car (entsel "\nSelect MTEXT: "))) (wcmatch (cdadr (entget mtxt)) "*TEXT")) (setq turns (getint "\nSpecify Number of Turns: ")) (setq ndlst (mapcar (function (lambda (x) (cdr (assoc 1 (entget (entnext x)))))) (list nd1 nd2))) (setq blk (vla-insertblock spc (vlax-3D-point (trans pt 1 0)) "NODE.dwg" 1. 1. 1. 0.)) (foreach att (vlax-safearray->list (vlax-variant-value (vla-getAttributes blk))) (cond ((eq "NODE1" (vla-get-TagString att)) (vla-put-TextString att (car ndlst))) ((eq "NODE2" (vla-get-TagString att)) (vla-put-TextString att (cadr ndlst))) ((eq "LENGTH" (vla-get-TagString att)) (vla-put-TextString att (rtos (vla-get-Length (vlax-ename->vla-object pl))))) ((eq "TURNS" (vla-get-TagString att)) (if turns (vla-put-TextString att (rtos turns)))) ((eq "COIL" (vla-get-TagString att)) (vla-put-TextString att (if mtxt (cdr (assoc 1 (entget mtxt))) "")))))) (princ "\n<!> No Point Selected <!>")) (princ "\n<!> Incorrect LINE Object Selection <!>")) (princ "\n<!> Incorrect Selection of NODE 2 <!>")) (princ "\n<!> Incorrect Selection of NODE 1 <!>")) (princ "\n<!> NODE Block not Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
chelsea1307 Posted May 29, 2009 Author Share Posted May 29, 2009 amazing as always thanks! 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.