Jump to content

Recommended Posts

Posted (edited)

Hi all

 

I am wondering if there is a chance to create a lisp which could hatch circular/rectangular objects which are on specific layers?

 

For example:

Layer1 - have various data including various dimensions circles/rectangles  ( some of them may overlap each over)

Layer2 - have various data including various dimensions circles/rectangles  ( some of them may overlap each over)

and so on...

 

 

Is there a way to run a lisp to hatch them as SOLID and put hatch on different layer called Features_Hatch ?

 

I hope I could explain clearly

 

Thank you for your help!

 

 

Edited by pyou
additional text
Posted

Just look at the -hatch command in lisp, you can do a ssget using filters '((0 . "Circle" "Lwpolyline")) then loop through the selection set.

 

(command "-hatch" "s" ent "" "P" "solid" "")

 

Have a go plenty here will help.

Posted

Don't need to loop through the selection set, just use it straight in the hatch

Edit the below to filter the selection set as you want (objects, layers, etc)

 

(defun c:test ( / Lay_Old MySS )
  (setq Lay_Old (getvar 'clayer))   ;record the current layer
  (setvar 'clayer "Features_Hatch") ;set the layer to Features_Hatch. This layer has to exist else error

  (setq MySS (ssget))              ; Select the objects you want, refer to http://www.lee-mac.com/selsetprocessing.html for filter options
  (command "-hatch" "s" MySS "" "P" "solid" "")  ; hatch the selection set

  (setvar 'clayer Lay_Old)         ; reset the layer to 'current layer'
  (princ)                          ; end quietly
) ; end function

 

Posted (edited)

Thank you Steven P and Bigal. I would need to create separate hatches for each circular/rectangular object and not just single hatch for all the objects.  Also where do i need to type specific layer names to hatch without selecting anything in cad? for example  layers called in cad  are named as Layer1; Layer2; etc.

 

Also a good tweak to the lisp would be to send hatch to the back 

 

Edited by pyou
Posted

This lisp almost working, how to make it work on 3dpolylines?

This time i have attached dwg example.

(defun c:test ( / Lay_Old MySS target_layers )
  (setq Lay_Old (getvar 'clayer))   ; Record the current layer
  (setvar 'clayer "Features_Hatch") ; Set the layer to Features_Hatch. This layer must exist else an error will occur

  ; Define a list of layers for hatching
  (setq target_layers '("Layer1" "Layer2" "Layer3"))

  (foreach layer_name target_layers
    (setq MySS (ssget "X" (list '(0 . "LWPOLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))
    (if MySS
      (progn
        (setq i 0)
        (repeat (sslength MySS)
          (setq ename (ssname MySS i))
          (command "-hatch" "S" ename "" "P" "Solid" "")
          (setq i (1+ i))
        )
      )
    )
  )

  (setvar 'clayer Lay_Old)  ; Reset the layer to the original current layer
  (princ)                  ; End quietly
)

 

 

 

test.dwg

  • Like 2
Posted

You forgot this put before hatch line.

 

(setvar 'clayer lay_name)

 

The filter for a 3dpoly is "Polyline".

 

  • Thanks 1
Posted
8 hours ago, BIGAL said:

The filter for a 3dpoly is "Polyline".

 

 

Could also do polyline as a wildcard, *, should get LW and 3D polylines

 

(setq MySS (ssget "X" (list '(0 . "*POLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))

 

(tip for the OP, type this in the command line and it will return the entity description, select the type you want and copy the entity type as required:

(Entget(Car(Entsel "Select Object")))

)

  • Thanks 1
Posted (edited)

Thank you all. 

The next step would be:

Some features are not only circles and rectangles but circular and triangle block reference objects. How do I include these to be hatches as well, please? Do i have to specify block reference names in the lisp to be hatch, or not necessary? I have attached test2 dwg example

 

Updated lisp so far:

(defun c:test ( / Lay_Old MySS target_layers )
  (setq Lay_Old (getvar 'clayer))   ; Record the current layer
  (setvar 'clayer "Features_Hatch") ; Set the layer to Features_Hatch. This layer must exist else an error will occur

  ; Define a list of layers for hatching
  (setq target_layers '("Layer1" "Layer2" "Layer3"))

  (foreach layer_name target_layers
    (setq MySS (ssget "X" (list '(0 . "*POLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))
    (if MySS
      (progn
        (setq i 0)
        (repeat (sslength MySS)
          (setq ename (ssname MySS i))
          (command "-hatch" "S" ename "" "P" "Solid" "")
          (setq i (1+ i))
        )
      )
    )
  )

  (setvar 'clayer Lay_Old)  ; Reset the layer to the original current layer
  (princ)                  ; End quietly
)

 

 

 

 

 

 

test2.dwg

Edited by pyou
Posted (edited)

I have managed to get it right , as it seems to work ok.

(defun c:test ( / Lay_Old MySS target_layers )
  (setq Lay_Old (getvar 'clayer)) ; Record the current layer
  (setvar 'clayer "Features_Hatch") ; Set the layer to Features_Hatch. This layer must exist else an error will occur

  ; Define a list of layers for hatching
  (setq target_layers '("Layer1" "Layer2" "Layer3"))

  ; Define a list of block names to hatch
  (setq block_names '("CIRCL" "Triangle"))

  (foreach layer_name target_layers
    (setq MySS (ssget "X" (list '(0 . "*POLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))
    (if MySS
      (progn
        (setq i 0)
        (repeat (sslength MySS)
          (setq ename (ssname MySS i))
          (command "-hatch" "S" ename "" "P" "Solid" "")
          (setq i (1+ i))
        )
      )
    )

    ; Hatch block references
    (foreach block_name block_names
      (setq MySS (ssget "X" (list '(0 . "INSERT") (cons 8 layer_name) (cons 2 block_name))))
      (if MySS
        (progn
          (setq i 0)
          (repeat (sslength MySS)
            (setq ename (ssname MySS i))
            (command "-hatch" "S" ename "" "P" "Solid" "")
            (setq i (1+ i))
          )
        )
      )
    )
  )

  (setvar 'clayer Lay_Old) ; Reset the layer to the original current layer
  (princ) ; End quietly
)

 

Edited by pyou
  • Like 1
Posted (edited)

I would like to change Hatch from SOLID to ANSI31 with a scale 0.03  , what changes do I need to make, please? I cant make scale to work.

Edited by pyou
Posted

Make the (if ss call a defun then no need for the code to be done twice.

 

Type -hatch look at the options line you will see what you need to add to (command "-hatch" ????

Posted (edited)

I cant make it to work (command "-hatch" "S" ename "" "P" "ANSI31" "" "A" 0 "S" 0.03 "")
Could someone be more specific, please.

Edited by pyou
Posted

Try a re-order

 

(command "-hatch" "P" "ANSI31" 0.03 0.0 "S" ename "" "")

 

  • Like 1
  • Thanks 1
Posted
On 10/15/2023 at 9:44 PM, pyou said:

Hello Pyou,
that is very good.
The only problem I have is that I can't use the all selection (ssget "X") but only a selection on the visible area of the screen.
Could you help me what I need to rewrite in your great Lisp?
Unfortunately I have no experience in Lisp.
Thanks!
Martin

 

 

 

 

This lisp almost working, how to make it work on 3dpolylines?

This time i have attached dwg example.

(defun c:test ( / Lay_Old MySS target_layers )
  (setq Lay_Old (getvar 'clayer))   ; Record the current layer
  (setvar 'clayer "Features_Hatch") ; Set the layer to Features_Hatch. This layer must exist else an error will occur

  ; Define a list of layers for hatching
  (setq target_layers '("Layer1" "Layer2" "Layer3"))

  (foreach layer_name target_layers
    (setq MySS (ssget "X" (list '(0 . "LWPOLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))
    (if MySS
      (progn
        (setq i 0)
        (repeat (sslength MySS)
          (setq ename (ssname MySS i))
          (command "-hatch" "S" ename "" "P" "Solid" "")
          (setq i (1+ i))
        )
      )
    )
  )

  (setvar 'clayer Lay_Old)  ; Reset the layer to the original current layer
  (princ)                  ; End quietly
)

 

 

 

test.dwg 22.75 kB · 4 downloads

 

Posted
14 hours ago, martinle said:

 

Hi martinle

 

unfortunately, I am not that experienced either, hopefully other group members could help you?

  • Like 1
Posted

Change this:

(setq MySS (ssget "X" (list '(0 . "LWPOLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))

 

to

 

(setq MySS (ssget "X" (list '(0 . "*POLYLINE,CIRCLE,ARC,RECTANGLE") (cons 8 layer_name))))

 

to also select 3d polylines.

 

Are you wanting to select all - using the LISP in the example drawing it selects everything for me. To select what you want with the mouse, take away the "X" in the lines above

 

 

 

 

Posted

Hello Steven,
Unfortunately it doesn't work if I just remove the X.
lg. Martin

Posted
On 18/10/2023 at 00:55, BIGAL said:

Try a re-order

 

(command "-hatch" "P" "ANSI31" 0.03 0.0 "S" ename "" "")

 

 

 

Thanks BIGAL, 

 

The issue I am facing now is if I start hatching objects  manually using random layer , it keeps it. If I run lisp after , it uses the layer I had selected and not the''Features_hatch'' and ''chamber_hatch''  layer to hatch all objects. Is there a way to get around it ? P.S it uses correct Hatch patterns just not the layers they should be on.

Posted
10 hours ago, martinle said:

Hello Steven,
Unfortunately it doesn't work if I just remove the X.
lg. Martin

 

That's odd, it works for me with your example file both selecting everything ....(ssget "x" (list (.... or selecting with the mouse .... (ssget (list (....

Posted
4 hours ago, pyou said:

 

 

Thanks BIGAL, 

 

The issue I am facing now is if I start hatching objects  manually using random layer , it keeps it. If I run lisp after , it uses the layer I had selected and not the''Features_hatch'' and ''chamber_hatch''  layer to hatch all objects. Is there a way to get around it ? P.S it uses correct Hatch patterns just not the layers they should be on.

 

 

I'm not getting that, can you post an example drawing? Should be something simple

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