Jump to content

Create user System Variables?


Happy Hobbit

Recommended Posts

I have a simple lisp that deletes text/mtext objects within certain coordinates of our A3 title block & it works well:

 (defun C:DTX (/ ss)
 (if (setq ss (ssget "_W" '(15 35) '(400 40) '((0 . "*TEXT"))))
   (command "_.erase" ss "")
   (alert "TEXT Not Found")
 );; End if
(princ)
)

However when it comes to our A0, A1 & A2 borders, with their various scales, the coordinates ['(15 35) '(400 40)] need to be either changed or a separate lisp created. Now the above coordinates could easily be stored in two variables, however we need the values of those variables to remain unchanged with different drawings or after a restart.

My idea is to create two system variables that the lisp can read from & the SV's can be changed using a separate lisp with getpoint functions. Anyone ever attempted to create system variables or global variables with semi permanent values?

Link to comment
Share on other sites

Presumably the dimensions of your borders at 1:1 scale are consistent across your drawings? If so, you could define the coordinates for the 1:1 scale blocks in your program and then scale/reposition/rotate these coordinates based on the scale, position & rotation of the the blocks found in each drawing.

 

Alternatively, you could store the exact coordinates in a drawing dictionary, but this seems pointless as the stored data would be rendered invalid if the position/scale/rotation of the titleblock is modified in any way.

Link to comment
Share on other sites

Unfortunately the borders are of varying scales, the A1 & A2 in particular range from 1:1 through to 1:6 with all scales in between (some NTS), the drawing scales are usually the same within each set, hence my idea to reset the coordinates of the deletion area when up-issuing a set of drawings with identical scales. Our usual method is to scroll though each drawing deleting such information as the date, ECN, 'by' & description of issue, then paste in the new information, which I've semi automated using diesel within the title block which detects the up-issue letter (A,B,C..) from the new filename (eg 912 15B) and a lisp which pastes, saves then scrolls to the next open drawing of which there may be 60 - 100.

My idea was to open all the drawings of a particular issue, then set the coordinates for the deletion area (if needed), then incorporate the defun DTX into a lisp that deletes, pastes, saves then scrolls to the next drawing in the set. It's only the storing of the coordinates across drawings which is giving me difficulty

Link to comment
Share on other sites

Unfortunately the borders are of varying scales, the A1 & A2 in particular range from 1:1 through to 1:6 with all scales in between (some NTS)

 

As I've noted above, the border scale does not matter providing that the same border blocks are used across your drawings - differences in the scale/position/rotation of the borders across the drawings is irrelevant as the window coordinates can be transformed accordingly.

Link to comment
Share on other sites

Alternatively, you could store the exact coordinates in a drawing dictionary

 

I think this may be the answer I am looking for, all the T blocks are always the same scale throughout the set, insertion point is always 0,0

 

I did consider using a simple text file to read/write to using a separate lisp, however a 'Drawing Dictionary' sounds better. The only problem is I've never even heard of them, let alone used one

Link to comment
Share on other sites

I think you're right Lee, I decided to go with the other option which is still being coded but seems to work ok. Will have to try it & maybe tweak the coordinates a bit & probably the block names which I can't remember as I'm not at work atm:

 

(defun c:testb ( / a1ll a1ur a2ll a2ur a3ll a3ur blk blkn i ll n scl ss ssw ur)
(setq a1ll '(425 49))
(setq a1ur '(685 56))
(setq a2ll '(178 49))
(setq a2ur '(438 56))
(setq a3ll '(12 49))
(setq a3ur '(275 56))  
 
(setq ss (ssget "_X" '((0 . "INSERT"))))
(setq i 0)
(repeat (sslength ss)
 (setq blk (entget(ssname ss i)))
(cond
	  ((wcmatch (cdr (assoc 2 blk)) "A1*")
	   (setq blkn (cdr (assoc 2 blk)))
	   (setq scl (cdr (assoc 41 blk)))
	   (setq ll (mapcar '(lambda (n) (* n scl)) a1ll))
	   (setq ur (mapcar '(lambda (n) (* n scl)) a1ur))
	  )
	  ((wcmatch (cdr (assoc 2 blk)) "A2*")
	   (setq blkn (cdr (assoc 2 blk)))
	   (setq scl (cdr (assoc 41 blk)))
	   (setq ll (mapcar '(lambda (n) (* n scl)) a2ll))
	   (setq ur (mapcar '(lambda (n) (* n scl)) a2ur))		   
	  )
)	  
 (setq i (1+ i))
)
    (princ (strcat "\nBlock Name is: "blkn))
    (princ (strcat "\nScale = " (rtos scl)))
 (if (setq ssw (ssget "_W" ll ur '((0 . "TEXT"))))
    (command "_.erase" ssw "")
    (alert "TEXT Not Found")
  );; End if
 (princ)
)

Link to comment
Share on other sites

I would structure your code in the following way:

(defun c:testb ( / blk ent enx idx lst scl sel ssw win )
   (setq lst
      '(
           ("A1*" (425 49) (685 56))
           ("A2*" (178 49) (438 56))
           ("A3*" ( 12 49) (275 56))
       )
   )
   (if (setq sel (ssget "_X" '((0 . "INSERT"))))
       (progn
           (setq idx -1)
           (while
               (and (setq ent (ssname sel (setq idx (1+ idx))))
                    (setq enx (entget ent)
                          blk (strcase (cdr (assoc 2 enx)))
                    )
                    (not (setq win (vl-some '(lambda ( x ) (if (wcmatch blk (car x)) (cdr x))) lst)))
               )
           )
           (if win
               (progn
                   (setq scl (cdr (assoc 41 enx))
                         win (mapcar '(lambda ( v s ) (mapcar '(lambda ( p ) (* p s)) v)) win (list scl scl))
                   )
                   ;; For debugging:
                   (princ "\nBlock name is: ")
                   (princ blk)
                   (princ "\nScale: ")
                   (princ scl)
                   (princ "\nCoordinates: ")
                   (princ win)
                   
                   (command "_.zoom" "_w" "_non" (car win) "_non" (cadr win))
                   
                   (if (setq ssw (apply 'ssget (append '("_W") win '(((0 . "TEXT"))))))
                       (repeat (setq idx (sslength ssw))
                           (entdel (ssname ssw (setq idx (1- idx))))
                       )
                       (princ "\nNo text found.")
                   )
               )
               (princ "\nNo matching blocks found.")
           )
       )
       (princ "\nNo blocks found.")
   )
   (princ)
)

The above is untested and assumes that your blocks are non-dynamic, uniformly scaled, and are always inserted at the origin with zero rotation.

Link to comment
Share on other sites

I would structure your code in the following way:

Thanks for that Lee, much neater than mine, quite reassuring that I got much of the functionality more or less correct (particularly the use of the mapcar/lambda function for multiplying the coordinates by the scale!)

....and assumes that your blocks are non-dynamic, uniformly scaled, and are always inserted at the origin with zero rotation

They are

Link to comment
Share on other sites

Lee's already got you pointed in the right direction for your desired task, so the only thing I can offer, lends to your ability to create custom system variables - for that, consider the Autoloader mechanism:

 

https://knowledge.autodesk.com/support/autocad/downloads/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-Customization/files/GUID-3C25E517-8660-4BB7-9447-2310462EF06F-htm.html

 

 

Cheers

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