Author Topic: A little Assistance required.  (Read 4091 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
A little Assistance required.
« on: March 11, 2004, 02:24:13 PM »
I need a little assistance on this lisp. Below is code for checking all entities in the drawings for Color/Linetype/Lineweight for BYLAYER. The problem I'm having is I want it to report to the user what the findings are as well as write the findings to a TEXT file only if there are any. If there are not any, then do not create a TEXT file.

Let's say it searched and found that there was only 3 objects with the linetype not set to BYLAYER. I need it to report and write to the text file the findings. If it found 3 objects with the linetype not set to BYLAYER and 5 objects with lineweights not BYLAYER, then I want it to report and write those findings etc....

Thanks for any help on this....

Don

Code: [Select]

(defun c:chkobjprops ()
(drawinginfo)
(getdate)
(setq badcolor 0)
(setq badlinetype 0)
(setq badlineweight 0)
(setq set1 (ssget "X"))
(setq setcount 0)
(repeat (sslength set1)
  (setq entityX (ssname set1 setcount))
  (setq entlistX (entget entityX))
  (if (null (cdr (assoc 62 entlistX)))
    (progn)
    (setq badcolor (+ badcolor 1))
  )
  (if (null (cdr (assoc 6 entlistX)))
    (progn)
    (setq badlinetype (+ badlinetype 1))
  )
  (if (null (cdr (assoc 370 entlistX)))
    (progn)
    (setq badlineweight (+ badlineweight 1))
  )
  (setq setcount (+ setcount 1))
)

;;**Items Color BYLAYER or not**
(if (= badcolor 0)
  (princ "\nAll object colors are BYLAYER.")
  (progn
(alert (strcat "\nLocated "
          (itoa badcolor)
          " objects with a color assigned."
          );end strcat
    )
      (setq openval (findfile valname))
      (if (null openval)
(setq valfile (open valname "w"))
(setq valfile (open valname "a"))
      )
(princ (strcat "VAL FILE CREATED ON: " DateTime) valfile)
    (princ "\n\nThere are " valfile)
    (princ badcolor valfile)
    (princ " objects with a color assigned." valfile)
    (princ "\n" valfile)
    (close valfile)
  )
)
;;**Items Color BYLAYER or not**

;;**Items Linetype BYLAYER or not**
(if (= badlinetype 0)
  (princ "\nAll object linetypes are BYLAYER.")
  (progn
(alert (strcat "\nLocated "
          (itoa badlinetype)
          " objects with a linetype assigned."
          );end strcat
    )
      (setq openval (findfile valname))
      (if (null openval)
(setq valfile (open valname "w"))
(setq valfile (open valname "a"))
      )
(princ (strcat "VAL FILE CREATED ON: " DateTime) valfile)
    (princ "\n\nThere are " valfile)
    (princ badlinetype valfile)
    (princ " objects with a linetype assigned." valfile)
    (princ "\n" valfile)
    (close valfile)
  )
)
;;**Items Linetype BYLAYER or not**

;;**Items Lineweight BYLAYER or not**
(if (= badlineweight 0)
      (princ "\nAll object lineweights are BYLAYER.")
      (progn
(alert (strcat "\nLocated "
          (itoa badlineweight)
          " objects with a lineweight assigned."
          );end strcat
    )
      (setq openval (findfile valname))
      (if (null openval)
(setq valfile (open valname "w"))
(setq valfile (open valname "a"))
      )
(princ (strcat "VAL FILE CREATED ON: " DateTime) valfile)
        (princ "\n\nThere are " valfile)
        (princ badlineweight valfile)
        (princ " objects with a lineweight assigned." valfile)
(princ "\n" valfile)        
(close valfile)        
      )
)
;;**Items Lineweight BYLAYER or not**
  (progn)
)

(defun drawinginfo ()
(setq drawname (getvar "dwgname"));get dwg name
(setq drawpath (getvar "dwgprefix"));get dwg path
(setq justname (substr drawname 1 (- (strlen drawname) 4)));get just the drawing name without extension
(setq valname (strcat drawpath justname ".val"));set path and val file name
)

(defun getdate ()
(setq D   (rtos (getvar "CDATE") 2 6)
      YR  (substr D 3 2)
      MO  (substr D 5 2)
      DAY (substr D 7 2))
(setq P_DATE (strcat MO "/" DAY "/" YR))
(setq D  (rtos (getvar "CDATE") 2 6)
      MT (substr D 10 2)
      MT (atoi MT))
(if (> MT 12)
(setq HR (- MT 12))
(setq HR MT)
)
(if (>= MT 12)
(setq TOD " PM")
(setq TOD " AM")
)
(setq HR (rtos HR 2 0))
(setq M  (substr D 12 2)
      S  (substr D 14 2))
(setq P_TIME (strcat HR ":" M ":" S TOD))
(setq DateTime (strcat p_date P_time))
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
A little Assistance required.
« Reply #1 on: March 11, 2004, 06:13:47 PM »
This is a simplified version, plus you'll have to add your stuff for the file name and date.
Code: [Select]

(defun c:find-if-not-bylayer (/ ss cntr ent entlst
                                not_bylayer_layer not_bylayer_lt
                                not_bylayer_lw fn fo)
  (gc)

  (setq ss (ssget "_x")
        cntr 0
        not_bylayer_layer 0
        not_bylayer_lt 0
        not_bylayer_lw 0
        )

  (while
    (setq ent (ssname ss cntr))

    (setq entlst (entget ent))

    (if (assoc 6 entlst)
      (setq not_bylayer_lt (1+ not_bylayer_lt))
      )

    (if (assoc 62 entlst)
      (setq not_bylayer_layer (1+ not_bylayer_layer))
      )

    (if (assoc 370 entlst)
      (setq not_bylayer_lw (1+ not_bylayer_lw))
      )

    (setq cntr (1+ cntr))

    ); while

  (setq ss nil)

  (gc)

  (if
    (vl-every
      '(lambda (x) (= x 0))
      (list not_bylayer_layer not_bylayer_lt not_bylayer_lw)
      )
    (alert "NO BYLAYER ITEMS FOUND")
    ; else
    (setq fn "c:\\_-stat-_.txt")
    )

  (if fn
    (progn
      (setq fo (open fn "w"))
      (write-line "The number of items that are _NOT_ bylayer" fo)
      (write-line
        (strcat (itoa not_bylayer_layer) " Items found for color")
        fo)
      (write-line
        (strcat (itoa not_bylayer_lt) " Items found for linetype")
        fo)
      (write-line
        (strcat (itoa not_bylayer_lw) " Items found for lineweight")
        fo)
      )
    )

  (close fo)
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
A little Assistance required.
« Reply #2 on: March 12, 2004, 10:01:44 AM »
Thanks for the code. But

1.) I only want the routine to create a TEXT file if it finds any of the 3 items not BYLAYER and I only want it to report in the TEXT file the incorrects items only.

2.) If all items are color BYLAYER and all items linetypes ar BYLAYER and there are some items with Lineweight assigned, then Create TEXT file and report that it found "" items with lineweights assigned.

What direction should I go in to accomplish this?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
A little Assistance required.
« Reply #3 on: March 12, 2004, 10:43:45 AM »
Perhaps this modification of mark's code will help.

Code: [Select]
(defun c:find-if-not-bylayer (/             ss            cntr
                              ent           entlst
                              not_bylayer_layer           not_bylayer_lt
                              not_bylayer_lw              fn
                              fo
                             )
  (gc)

  (setq ss (ssget "_x")
        cntr 0
        not_bylayer_layer
         0
        not_bylayer_lt
         0
        not_bylayer_lw
         0
  )

  (while
    (setq ent (ssname ss cntr))

     (setq entlst (entget ent))

     (if (assoc 6 entlst)
       (setq not_bylayer_lt (1+ not_bylayer_lt))
     )

     (if (assoc 62 entlst)
       (setq not_bylayer_layer (1+ not_bylayer_layer))
     )

     (if (assoc 370 entlst)
       (setq not_bylayer_lw (1+ not_bylayer_lw))
     )

     (setq cntr (1+ cntr))

  ) ; while

  (setq ss nil)

  (gc)

  (if
    (vl-every
      '(lambda (x) (= x 0))
      (list not_bylayer_layer not_bylayer_lt not_bylayer_lw)
    )
     (alert "NO BYLAYER ITEMS FOUND")
 ; else
     (setq fn "c:\\_-stat-_.txt")
  )

  (if fn
    (progn
      (if (findfile fn)
        (setq fo (open fn "a"))
        (setq fo (open fn "w"))
      )
      (princ (strcat "VAL FILE CREATED ON: " datetime) valfile)

      (write-line "The number of items that are _NOT_ bylayer" fo)
      (if (> not_bylayer_layer 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_layer) " Items found for color")
          )
          (write-line
            (strcat (itoa not_bylayer_layer) " Items found for color")
            fo
          )
        )
      )
      (if (> not_bylayer_layer 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_lt) " Items found for linetype")
          )
          (write-line
            (strcat (itoa not_bylayer_lt) " Items found for linetype")
            fo
          )
        )
      )
      (if (> not_bylayer_layer 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_lw) " Items found for lineweight")
          )
          (write-line
            (strcat (itoa not_bylayer_lw) " Items found for lineweight")
            fo
          )
        )
      )
      (princ "\nEnd Entry--> " fn)
    )
  )
  (close fo)
  (princ)
)

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
A little Assistance required.
« Reply #4 on: March 12, 2004, 11:20:21 AM »
What's wrong with selection filters?

Code: [Select]
(setq customColor (cons "Custom color" (ssget "X" '((-4 . "<")(62 . 256))))
      customLType (cons "Custom linetype" (ssget "X" '((6 . "~Bylayer"))))
      customLWght (cons "Custom lineweight" (ssget "X" '((-4 . ">=")(370 . 0))))
)

(foreach n (list customColor customLType customLWght)
  (mapcar 'princ (list "\n" (car n) ": "
                       (if (cdr n) (sslength (cdr n)) 0))
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
A little Assistance required.
« Reply #5 on: March 12, 2004, 11:59:33 AM »
How elegant, wish I could do that. :roll:

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
A little Assistance required.
« Reply #6 on: March 12, 2004, 01:46:30 PM »
Thanks guys for the input. Much appreciated. Here is the final code.

Code: [Select]

(defun c:chkobjprops (/             ss            cntr
                              ent           entlst
                              not_bylayer_layer           not_bylayer_lt
                              not_bylayer_lw              fn
                              valfile
                             )
(setq valname "c:\\_-stat-_.txt")
  (gc)
  (setq ss (ssget "_x")
        cntr 0
        not_bylayer_layer
         0
        not_bylayer_lt
         0
        not_bylayer_lw
         0
  )
  (while
    (setq ent (ssname ss cntr))
     (setq entlst (entget ent))
     (if (assoc 6 entlst)
       (setq not_bylayer_lt (1+ not_bylayer_lt))
     )
     (if (assoc 62 entlst)
       (setq not_bylayer_layer (1+ not_bylayer_layer))
     )
     (if (assoc 370 entlst)
       (setq not_bylayer_lw (1+ not_bylayer_lw))
     )
     (setq cntr (1+ cntr))
  )
  (setq ss nil)
  (gc)
  (if
    (vl-every
      '(lambda (x) (= x 0))
      (list not_bylayer_layer not_bylayer_lt not_bylayer_lw)
    )
     (alert "No NON-BYLAYER items found")
    (progn
    (drawinginfo)
        (setq openval (findfile valname))
        (if (null openval)
  (setq valfile (open valname "w"))
  (setq valfile (open valname "a"))
        )
        (getdate)
        (princ (strcat "VAL FILE CREATED ON: " DateTime) valfile)
        (princ "\n" valfile)
      (princ "\nThe number of items that are NOT BYLAYER\n" valfile)
      (princ "\n" valfile)
      (if (> not_bylayer_layer 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_layer) " Items found for color")
          )
          (write-line (strcat (itoa not_bylayer_layer) " Items found for color") valfile)
          (princ "\n" valfile)
        )
      )
      (if (> not_bylayer_lt 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_lt) " Items found for linetype")
          )
          (write-line (strcat (itoa not_bylayer_lt) " Items found for linetype") valfile)
          (princ "\n" valfile)
        )
      )
      (if (> not_bylayer_lw 0)
        (progn
          (prompt
            (strcat (itoa not_bylayer_lw) " Items found for lineweight")
          )
          (write-line (strcat (itoa not_bylayer_lw) " Items found for lineweight") valfile)
          (princ "\n" valfile)
        )
      )
(close valfile)      
    )
  )
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023