Jump to content

LISP to insert two attributes, pline length, and mtext into block


chelsea1307

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • chelsea1307

    11

  • doru10

    2

Top Posters In This Topic

Posted Images

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?

Link to comment
Share on other sites

just pulling the number from the node blocks

the new block would read

node#

node#

length

mtext

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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