Jump to content

Recommended Posts

Posted

Hello everyone,

 

I've made a simple Lisp that allows you to change the properties of certain layers and then hatch the objects on that layer with the autocad command -Layer and -Hatch.

 

(defun c:ExecuterFonctions (/)
  (c:Layer01211)
  (c:Layer01251)
  (c:AppliquerDUCalque)
  
)



(defun c:Layer01211 (/ ss layerName)
  (setq layerName "01211")

  (if (tblsearch "LAYER" layerName)
    (progn
      ;; Set all polylines on the specified layer to continuous line with thickness 0.125 and color (0 0 0)
      (command
        "-CALQUE"
        "E"
        layerName
        "CO"
        "blanc"
        layerName
        "TL"
        "CONTINUOUS"
        layerName
        "EP"
        "0.125"
        layerName
        ""
      )

      ;; Hatch all closed polylines on the specified layer with a solid hatch and color (172 172 172)
      (command
        "-HACHURES"
        "P"
        "SOLID"
        "COU"
        "U"
        "172,172,172"
        "S"
        (ssget "X" (list (cons 8 "01211"))) ; Select all objects on layer 01211
        ""
        ""
      )
    
      (prompt (strcat "\nPolygons on layer " layerName " hatched and boundary set."))
    )
    (prompt "\nLayer not found.")
  )

  (princ)
)
(defun c:Layer01251 (/ ss layerName)
  (setq layerName "01251")

  (if (tblsearch "LAYER" layerName)
    (progn
      ;; Set all polylines on the specified layer to continuous line with thickness 0.20 and color (0 0 0)
      (command
        "-CALQUE"
        "E"
        layerName
        "CO"
        "blanc"
        layerName
        "TL"
        "CONTINUOUS"
        layerName
        "EP"
        "0.20"
        layerName
        ""
      )

      ;; Hatch all closed polylines on the specified layer with a solid hatch and color (230 230 230)
      (command
        "-HACHURES"
        "P"
        "DOTS"
        "1.333"
        "100" 
        "COU"
        "U"
        "120,120,120"
        "." ;; Aucune couleur de fond
        "S"
        (ssget "X" (list (cons 8 "01251"))) ; Select all objects on layer 01251
        ""
        ""
      )
    
      (prompt (strcat "\nPolygons on layer " layerName " hatched and boundary set."))
    )
    (prompt "\nLayer not found.")
  )

  (princ)
)

(defun c:AppliquerDUCalque (/ ss)
  ;; Sélectionner tous les objets dans le dessin
  (setq ss (ssget "X"))
  
  (if ss
    (progn
      ;; Récupérer les propriétés du calque courant
      (setq currentLayerProps (tblsearch "LAYER" (getvar "CLAYER")))
      
      ;; Mettre à jour chaque objet dans la sélection
      (foreach obj (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
        (entmod
          (append
            (entget obj)
            currentLayerProps
          )
        )
      )
      
      (prompt "\nPropriétés du calque appliquées à tous les objets.")
    )
    (prompt "\nAucun objet trouvé dans le dessin.")
  )
  
  (princ)
)

 

I have a problem with hatching in my using the functions in my lisp. I use two layers - one for solid hatching and another for dotted hatching. The issue arises when I use the function for solid hatching first (Layer01211) and then try to switch to dotted hatching (Layer01251). It seems like it remembers the solid hatch and doesn't wait for the background color, which is needed for dotted hatching. On the other hand, if I start with dotted hatching (Layer01251) and then switch to solid hatching (Layer01211), it expects a background color even though it shouldn't be required for solid hatching.

 

I'm wondering if there's a way to reset the hatch settings at the beginning of the command so that it doesn't remember the last used hatch.

 

Any ideas or suggestions would be appreciated. :)

 

Thank you

Posted

Maybe try this not tested

 

(setvar 'hpname "DOTS")
(command
        "-HACHURES"
        "P"
        ""

 

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