Jump to content

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


chelsea1307

Recommended Posts

  • 2 years later...
  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • chelsea1307

    11

  • doru10

    2

Top Posters In This Topic

Posted Images

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

 

Very interesting LISP Lee-Mac.

It can automatically change node value to the block (after the RE command), when the value PNODE edit and / or length of the polyline?

Sincerely,

Doru

Label and Node.dwg

Link to comment
Share on other sites

Very interesting LISP Lee-Mac.

It can automatically change node value to the block (after the RE command), when the value PNODE edit and / or length of the polyline?

Sincerely,

Doru

 

There would probably be a way using Fields to link the values, however this is such old code I would most likely rewrite the whole thing :oops:

Link to comment
Share on other sites

There would probably be a way using Fields to link the values, however this is such old code I would most likely rewrite the whole thing :oops:

Thanks for the reply.

I thought that I add variations and lines as your existing lisp.

I'm beginning to programming and trying to discover and understand as much.

Thank you sincerely.

Doru

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