Jump to content

Bad DXF Group


RocketBott

Recommended Posts

I am trying to change an attribute with the value of another attribute in my title block and think I am almost there but do not know what I have to do to the variable 0chk to use it as shown below. If it is replaced with a string i.e. "RR" all works fine. The help file suggests cons requires a list-or-atom?

 

 
(defun C:modchk (/)
 (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "*BORDER*")
      (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB"))
             (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (foreach ent (mapcar 'cadr (ssnamex ss))
   (setq att (entnext ent))
   (while (not (eq "SEQEND" (cdadr (entget att))))
     (cond ((eq "YEAR" (cdr (assoc 2 (entget att))))
        (entmod (subst (cons 1 year) (assoc 1 (entget att)) (entget att))))
  ((eq "0CHECKED" (cdr (assoc 2 (entget att))))
  (setq 0chk (cdr (assoc 1 (entget att)))))
  ((eq "0DDATE" (cdr (assoc 2 (entget att))))
  (setq 0dat (cdr (assoc 1 (entget att))))
  (if (>(strlen 0dat) 5)
        (entmod (subst (cons 1 0chk) (assoc 1 (entget att)) (entget att))))))
     (setq att (entnext att))))
     (command "_regenall"))
   (princ "\n<!> No Blocks Found <!>"))
(princ))

 

I feel like I should know this but have spent too long looking already so any help would be appreaciated (even just pointed at a sectin of the help or a web page).

 

Thanks

Link to comment
Share on other sites

Hi RocketBott,

 

I can't quite see what you are trying to achieve from the code - it also looks as though your variable 'year' is not defined.

 

Could you explain exactly what attribute tags are to be populated with which values please?

 

Lee

Link to comment
Share on other sites

Not sure if this comes close to what you are trying to achieve?

 

(defun c:modchk ( / _Subst _dxf year ss )
 ;; © Lee Mac 2010

 (setq year "2010")

 (defun _Subst ( key value elist )
   (if
     (setq elist
       (entmod
         (subst
           (cons key value) (assoc key elist) elist
         )
       )
     )
     (entupd (cdr (assoc -1 elist)))
   )
 )

 (defun _dxf ( key elist ) (cdr (assoc key elist)))

 (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*BORDER*") (66 . 1))))
   (
     (lambda ( i / e el tag chk )        
       (while (setq e (ssname ss (setq i (1+ i))))          
         (while
           (not
             (eq "SEQEND"
               (_dxf 0
                 (setq el
                   (entget
                     (setq e (entnext e))
                   )
                 )
               )
             )
           )
           (cond
             ( (eq "YEAR" (setq tag (_dxf 2 el)))

               (_Subst 1 year el)
             )
             ( (eq "0CHECKED" tag)

               (setq chk (_dxf 1 el))
             )
             ( (eq "0DDATE" tag)

               (if (and chk (< 5 (strlen (_dxf 1 el))))
                 (_Subst 1 chk el)
               )
             )
           )
         )
       )
     )
     -1
   )
   (princ "\n--> No Border Blocks Found <--")
 )

 (princ)
)

 

BTW, these may help you in future:

 

http://lee-mac.com/attributefunctions.html

Link to comment
Share on other sites

Hi Lee,

 

Here is the complete code.

I am redefining the Titlt block in a drawing and changing the Year attribute to the current year - this works fine - then checking the 0DDATE att to see if it is more than 5 characters and if it is change it to the same as the 0CHECKED att.

 

It appears the 0chk att is set to nil whick causes the error.

 

 
(defun c:rb (/)
(setq curryr (rtos(GETVAR "CDATE")2 6))
(setq year (substr curryr 1 4))
(command "-purge" "a" "" "n")
(if (setq ss (ssget "X" '((2 . "A1_BORDER")))) (command "._-insert" "A1_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A1_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A0_BORDER")))) (command "._-insert" "A0_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A2_BORDER")))) (command "._-insert" "A2_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A2_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A2_BORDER")))) (command "._-insert" "A3_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A3_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A0_Border_Primary")))) (command "._-insert" "A0_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border_Primary.dwg" nil))
 (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "*BORDER*")
      (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB"))
             (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
     (foreach ent (mapcar 'cadr (ssnamex ss))
   (setq att (entnext ent))
   (while (not (eq "SEQEND" (cdadr (entget att))))
     (cond ((eq "YEAR" (cdr (assoc 2 (entget att))))
        (entmod (subst (cons 1 year) (assoc 1 (entget att)) (entget att))))
  ((eq "0CHECKED" (cdr (assoc 2 (entget att))))
  (setq 0chk (cdr (assoc 1 (entget att)))))
  ((eq "0DDATE" (cdr (assoc 2 (entget att))))
  (setq 0dat (cdr (assoc 1 (entget att))))
  (if (>(strlen 0dat) 5)
        (entmod (subst (cons 1 0chk) (assoc 1 (entget att)) (entget att))))))
     (setq att (entnext att))))
     (command "_regenall"))
   (princ "\n<!> No Blocks Found <!>"))
(princ))

 

Thanks

Link to comment
Share on other sites

Maybe something like this?

 

(Completely untested)

 

(defun c:rb ( / *error* _ReDefine _Subst _dxf year ocm ss )
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (if ocm (setvar 'CMDECHO ocm))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _ReDefine ( block filename / fn )
   (if (ssget "_X" (list (cons 0 "INSERT") (cons 2 block)))
     (if (setq fn (findfile filename))
       (command "_.-insert" (strcat block "=" fn) nil)
       (princ (strcat "\n** " filename " not found **"))
     )
   )
 )
 
 (defun _Subst ( key value elist )
   (if
     (setq elist
       (entmod
         (subst
           (cons key value) (assoc key elist) elist
         )
       )
     )
     (entupd (cdr (assoc -1 elist)))
   )
 )

 (defun _dxf ( key elist ) (cdr (assoc key elist)))

 (setq year (LM:GetDate "YYYY") ocm (getvar 'CMDECHO))
 
 (setvar 'CMDECHO 0)
 (command "_.-purge" "_A" "" "_N")

 (mapcar '_ReDefine
   '("A1_BORDER" "A0_BORDER" "A2_BORDER" "A3_BORDER" "A0_Border_Primary")
   '("F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A1_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A2_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A3_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_Border_Primary.dwg"
    )
 )

 (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*BORDER*") (66 . 1))))
   (
     (lambda ( i / e el tag chk )        
       (while (setq e (ssname ss (setq i (1+ i))))          
         (while
           (not
             (eq "SEQEND"
               (_dxf 0
                 (setq el
                   (entget
                     (setq e (entnext e))
                   )
                 )
               )
             )
           )
           (cond
             ( (eq "YEAR" (setq tag (_dxf 2 el)))

               (_Subst 1 year el)
             )
             ( (eq "0CHECKED" tag)

               (setq chk (_dxf 1 el))
             )
             ( (eq "0DDATE" tag)

               (if (and chk (< 5 (strlen (_dxf 1 el))))
                 (_Subst 1 chk el)
               )
             )
           )
         )
       )
     )
     -1
   )
   (princ "\n--> No Border Blocks Found <--")
 )

 (command "_.regenall")
 (setvar 'CMDECHO ocm)  
 (princ)
)

;;---------------------=={ Get Date }==-----------------------;;
;;                                                            ;;
;;  Returns a string containing the current date/time in the  ;;
;;  specified format                                          ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  format  - DIESEL edtime string specifying format          ;;
;;------------------------------------------------------------;;
;;  Returns:  Date/time string                                ;;
;;------------------------------------------------------------;;

(defun LM:GetDate ( format )
 ;; © Lee Mac 2010
 (menucmd (strcat "m=$(edtime,$(getvar,DATE)," format ")"))
)

Link to comment
Share on other sites

Thanks Lee but your code did not work either (no errors just did not change the 0DDATE att) but after having a peek at your web site (now bookmarked) I have got it to work.

The code you posted will take a while for me to decipher so I will go with what I have and not take up any more of you sought after time.

Thank you very much for your help.

 

 
(defun c:rb (/)
(setq curryr (rtos(GETVAR "CDATE")2 6))
(setq year (substr curryr 1 4))
(command "-purge" "a" "" "n")
(if (setq ss (ssget "X" '((2 . "A1_BORDER")))) (command "._-insert" "A1_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A1_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A0_BORDER")))) (command "._-insert" "A0_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A2_BORDER")))) (command "._-insert" "A2_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A2_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A2_BORDER")))) (command "._-insert" "A3_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A3_border.dwg" nil))
(if (setq ss (ssget "X" '((2 . "A0_Border_Primary")))) (command "._-insert" "A0_BORDER=F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border_Primary.dwg" nil))
 (if (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "*BORDER*")
      (cons 66 1)(if (getvar "CTAB")(cons 410 (getvar "CTAB"))
             (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
  (setq 0chk
     (LM:GetAttributeValue (ssname ss 0) "0CHECKED")
     (foreach ent (mapcar 'cadr (ssnamex ss))
   (setq att (entnext ent))
   (while (not (eq "SEQEND" (cdadr (entget att))))
     (cond ((eq "YEAR" (cdr (assoc 2 (entget att))))
        (entmod (subst (cons 1 year) (assoc 1 (entget att)) (entget att))))
  ((eq "0DDATE" (cdr (assoc 2 (entget att))))
  (setq 0dat (cdr (assoc 1 (entget att))))
  (if (>(strlen 0dat) 5)
        (entmod (subst (cons 1 0chk) (assoc 1 (entget att)) (entget att))))))
     (command "_regenall"))
   (princ "\n<!> No Blocks Found <!>"))
(princ))
(defun LM:GetAttributeValue ( block tag / value elist )
 ;; © Lee Mac 2010
 (while
   (not
     (or
       (eq "SEQEND"
         (cdr
           (assoc 0
             (setq elist
               (entget
                 (setq block (entnext block))
               )
             )
           )
         )
       )
       value
     )
   )
   (if (eq tag (cdr (assoc 2 elist)))
     (setq value (cdr (assoc 1 elist)))
   )
 )
)

Link to comment
Share on other sites

You're welcome :)

 

Looking at the modification you made to your code, I understand that it doesn't matter which '0CHECKED' value is used, so I would perhaps propose this:

 

(defun c:rb ( / *error* _ReDefine _Subst _dxf year ocm ss )
 ;; © Lee Mac 2010

 (defun *error* ( msg )
   (if ocm (setvar 'CMDECHO ocm))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _ReDefine ( block filename / fn )
   (if (ssget "_X" (list (cons 0 "INSERT") (cons 2 block)))
     (if (setq fn (findfile filename))
       (command "_.-insert" (strcat block "=" fn) nil)
       (princ (strcat "\n** " filename " not found **"))
     )
   )
 )
 
 (defun _Subst ( key value elist )
   (if
     (setq elist
       (entmod
         (subst
           (cons key value) (assoc key elist) elist
         )
       )
     )
     (entupd (cdr (assoc -1 elist)))
   )
 )

 (defun _dxf ( key elist ) (cdr (assoc key elist)))

 (setq year (LM:GetDate "YYYY") ocm (getvar 'CMDECHO))
 
 (setvar 'CMDECHO 0)
 (command "_.-purge" "_A" "" "_N")

 (mapcar '_ReDefine
   '("A1_BORDER" "A0_BORDER" "A2_BORDER" "A3_BORDER" "A0_Border_Primary")
   '("F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A1_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A2_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A3_border.dwg"
     "F:\\ENGINEER\\GENERIC\\Edinburgh_Ring\\Symbols\\A0_Border_Primary.dwg"
    )
 )

 (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*BORDER*") (66 . 1))))
   (
     (lambda ( i / e el tag chk v )        
       (while (setq e (ssname ss (setq i (1+ i))))          
         (while
           (not
             (eq "SEQEND"
               (_dxf 0
                 (setq el
                   (entget
                     (setq e (entnext e))
                   )
                 )
               )
             )
           )
           (cond
             ( (eq "YEAR" (setq tag (_dxf 2 el)))

               (_Subst 1 year el)
             )
             ( (eq "0CHECKED" tag)

               (setq chk (cond ( (/= "" (setq v (_dxf 1 el))) v ) ( chk )))
             )
             ( (eq "0DDATE" tag)

               (if (and chk (< 5 (strlen (_dxf 1 el))))
                 (_Subst 1 chk el)
               )
             )
           )
         )
       )
     )
     -1
   )
   (princ "\n--> No Border Blocks Found <--")
 )

 (command "_.regenall")
 (setvar 'CMDECHO ocm)  
 (princ)
)

;;---------------------=={ Get Date }==-----------------------;;
;;                                                            ;;
;;  Returns a string containing the current date/time in the  ;;
;;  specified format                                          ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  format  - DIESEL edtime string specifying format          ;;
;;------------------------------------------------------------;;
;;  Returns:  Date/time string                                ;;
;;------------------------------------------------------------;;

(defun LM:GetDate ( format )
 ;; © Lee Mac 2010
 (menucmd (strcat "m=$(edtime,$(getvar,DATE)," format ")"))
)

Lee

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