Jump to content

Select Hatch Pattern by Scale and pattern


3dwannab

Recommended Posts

I was hoping to get help with a LISP to:

 

 

  • Select a hatch
  • The lisp then takes the scale size and hatch pattern name and selects the same hatches with those attributes.
  • I can then globally and manually change them in the properties dialog.

This is particularly useful when adjusting hatch scales.

 

 

I'm not worried about layers, colors etc.

 

Just these two properties. Thanks.

 

 

My lisp knowledge is basic: I know how to select only hatches via below but I'd like to know how to get the info from whats picked and use that info:

(defun c:QS_HATCH_ALL (/ ss)
 (if (setq ss (ssget '((0 . "HATCH"))))
   (princ (strcat "\nNumber of found hatches : < " (itoa (sslength ss)) " >"))
   (princ "\n***  Nothing Selected  ***")
 )
 (sssetfirst nil ss)
 (princ)
)

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • 3dwannab

    12

  • Tharwat

    7

  • eyeofnewt555

    2

  • BIGAL

    1

Try this

(setq ent (entget (car (entsel "Pick a hatch"))))
(setq hname (cdr (assoc 2 ent)))
(setq sc (cdr (assoc 41 ent)))
(setq ss (ssget (list (cons 0 "HATCH")(cons 2 hname)(cons 41 sc))))

Link to comment
Share on other sites

Try this UNTESTED codes.

 

(defun c:qs_hatch (/ s e ss)
 (princ "\nPick on hatch object to select similar with Pattern name & Scale :")
 (and (setq s (ssget "_+.:S:E" '((0 . "HATCH"))))
      (setq e (entget (ssname s 0)))
      (setq ss (ssget "_X"
                      (list '(0 . "HATCH")
                            (assoc 2 e)
                            (assoc 41 e)
                            (cons 410 (getvar 'ctab))
                      )
               )
      )
 )
 (sssetfirst nil ss)
 (princ)
)

Link to comment
Share on other sites

Try this

(setq ent (entget (car (entsel "Pick a hatch"))))
(setq hname (cdr (assoc 2 ent)))
(setq sc (cdr (assoc 41 ent)))
(setq ss (ssget (list (cons 0 "HATCH")(cons 2 hname)(cons 41 sc))))

Tried this but didn't work I'm afraid. Probably something I did.

(defun c:test ( \hname sc ss)

(setq ent (entget (car (entsel "Pick a hatch"))))
(setq hname (cdr (assoc 2 ent)))
(setq sc (cdr (assoc 41 ent)))
(setq ss (ssget (list (cons 0 "HATCH")(cons 2 hname)(cons 41 sc))))

;;(sssetfirst nil ss)

) ;_  end defun

 

 

Tharwat

 

Thank you Thank you. Don't know how I managed without this before now!

 

What does the line do:

(setq s (ssget "_+.:S:E" '((0 . "HATCH"))))

Link to comment
Share on other sites

 

Tharwat

 

Thank you Thank you. Don't know how I managed without this before now!

 

What does the line do:

(setq s (ssget "_+.:S:E" '((0 . "HATCH"))))

 

You're welcome.

 

That line with the ssget function is to allow the user to pick only ONE object and the we have only one object name which is HATCH in the previous example.

Link to comment
Share on other sites

You're welcome.

 

That line with the ssget function is to allow the user to pick only ONE object and the we have only one object name which is HATCH in the previous example.

I see thank you.

 

Just noticed one thing I never thought of was a solid hatch which doesn't have scale (I think) as the LISP fails when selecting it. I know shows up in the properties but the LISP should still work.

 

Would it be hard to make the LISP work when selecting soild hatch only:

- select it with the same pattern, layer AND color as opposed my previous request.

- if I select any other type hatch the previous LISP takes care of them.

Link to comment
Share on other sites

This should work .

 

(defun c:qs_hatch (/ s e ss c fltr)
 ;; Tharwat 06.Dec.2015 ;;
 (princ
   "\nPick on hatch object to select similar with Pattern name & Scale :"
 )
 (and (setq s (ssget "_+.:S:E" '((0 . "HATCH"))))
      (setq e (entget (ssname s 0)))
      (setq fltr (list (assoc 8 e)
                       (if (setq c (assoc 62 e))
                         c
                         '(62 . 256)
                       )
                 )
      )
      (if (eq (cdr (assoc 2 e)) "SOLID")
        (setq fltr (append fltr (list (assoc 2 e))))
        (setq fltr (list (assoc 2 e) (assoc 41 e)))
      )
      (setq ss (ssget "_X"
                      (append '((0 . "HATCH"))
                              (list (cons 410 (getvar 'ctab)))
                              fltr
                      )
               )
      )
 )
 (sssetfirst nil ss)
 (princ)
)

Edited by Tharwat
Link to comment
Share on other sites

Thanks for that. But if I select a solid hatch it selects other hatch patterns on the same layer also.

 

To recap:

- For solid hatches - select same pattern name, layer, color

- For all others - the first method you wrote.

Link to comment
Share on other sites

Codes updated above.

Attached is drawing. Still the same. If I select the solid hatch for the glazing it selects other hatch patterns too. It's a true color so maybe that's an issue?

 

test dwg.dwg

Link to comment
Share on other sites

Sorry , I forgot to add the pattern name with the filter and that's why it did select the rest of the other pattern names when you pick a solid.

 

Anyway codes updated above.

Link to comment
Share on other sites

Ah, append added!! It was a simple fix. I really need to learn LISP. I'm learning max script so I don't want to melt my brain altogether!!

 

Thanks very much :)

Link to comment
Share on other sites

  • 1 year later...
This should work .

 

Aaaand, hope you're still paying attention over a year later. How could the filters on this be edited to ignore differences in scale and to only select hatches on the same layer as the one originally selected?

 

Also, would it be difficult to have this work on multiple hatches? Let's say I select one instance of hatch "A" and one instance of hatch "B" -- could it grab all instances of both of those hatches on same layer? Basically, the way SelectSimilar works.

 

Thanks for any help!

Link to comment
Share on other sites

Aaaand, hope you're still paying attention over a year later. How could the filters on this be edited to ignore differences in scale and to only select hatches on the same layer as the one originally selected?

 

Also, would it be difficult to have this work on multiple hatches? Let's say I select one instance of hatch "A" and one instance of hatch "B" -- could it grab all instances of both of those hatches on same layer? Basically, the way SelectSimilar works.

 

Thanks for any help!

 

Hi,

 

This is my first LISP. I was lazy the last two years so, I sat down for the last day or so to finally learn the basics anyway.

I'm also sure that some LISP masters out there could write this in a 1/2 a line :geek: but any comments from them on it would be nice. 8)

 

With this LISP you can select any object and that in turn, will select any hatch on that objects layer. You don't need to select a hatch for it to work which is nice.

 

 

Here you go: (I've left some help links in there that helped me write it):

 

Syntax to run command is 'QSH' or 'QS_Hatch_On_Same_Layer'

; Select hatches on same layer by 3dwannab
; 09.02.2017
; Usage: Select any object to select hatches on that layer
; uncomment below to get alart that selection is not 'HATCH'

(defun c:QSH nil (c:QS_Hatch_On_Same_Layer))
(defun c:QS_Hatch_On_Same_Layer ( / ss layName )

(while (not (setq ss (car (entsel "\nSelect object:\n\nSelects hatches\non layer >>> ")))))

(cond
	((/= nil ss)
		(progn
			(setq layName (cdr (assoc 8 (entget ss))))
			(setq ss (ssget "X" (list (cons 8 layName) '(0 . "HATCH") (cons 410 (getvar 'ctab)))))
			(if ss
				(
					(progn
						(princ (strcat "\n" (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " selected"))
						(sssetfirst nil ss)
						)
					)
				(alert (strcat (getvar "loginname") ", no hatch on layer:\n\n'" layName "' exists in '" (getvar "ctab") "'."))
				)
			)
		)
	)

(princ)

)

(princ "\n:: QS_Hatch_On_Same_Layer.lsp | Version 1.0 | by 3DwannaB ::")
(princ "\n:: Type \"QS_Hatch_On_Same_Layer\" OR \"QSH\" to Invoke ::") (princ)

; Some help can be found here that helped me along the way:
; ------------------------------------------------------------
; http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BE77062-C359-4D01-915B-69CF672C653B
; http://www.lee-mac.com/ssget.html
; http://www.cadtutor.net/forum/showthread.php?55964-How-to-select-the-blocks-only-in-current-space-(either-model-or-paper-space)&p=421701&viewfull=1#post421701

Link to comment
Share on other sites

Neat! congrats on your first lisp! I'm hoping to get to that point one day!

 

If you're up for more practice, do you think it could still filter by patter name? So grab a hatch and run the lisp and it grabs all hatches of the same name on the same layer?

Link to comment
Share on other sites

Neat! congrats on your first lisp! I'm hoping to get to that point one day!

 

If you're up for more practice, do you think it could still filter by patter name? So grab a hatch and run the lisp and it grabs all hatches of the same name on the same layer?

 

Love the practice! It's additive. With this, I've went down a different route using the vla method which IMO is easier to understand. This took an hour to write. The other took me over a day ! :facepalm:

 

BUT, my advice is, don't be scared and try to learn it.

 

I've put links to where I got help in the code below.

 

; Select hatches on same layer & pattern by 3dwannab
; 09.02.2017
; v1.1
; Usage: Select hatch to select other hatches on similar Layer and pattern

(vl-load-com)

(defun c:QSH nil (c:QS_Hatch_Same_Layer&Pattern))
(defun c:QS_Hatch_Same_Layer&Pattern ( / ss layName hatchName )

(setq ss nil)

(while (= ss nil)

	(setq ss (vlax-ename->vla-object (car (entsel "\nSelect hatch to select similar\nlayer & pattern: "))))

	(cond

		((= "AcDbHatch" (vla-get-ObjectName ss)) ;; cond 1 - is a hatch object
			(progn

				(setq hatchName (vla-get-PatternName ss))
				(setq layName (vla-get-Layer ss))

				(setq ss (ssget "X" (list (cons 8 layName) '(0 . "HATCH") (cons 2 hatchName) (cons 410 (getvar 'ctab)))))
				(princ (strcat "\n   >>>   " (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " selected   <<<   "))

				(sssetfirst nil ss)(princ)
				)

			)

		((/= "AcDbHatch" (vla-get-ObjectName ss)) ; cond 2 - not a hatch object
			(princ "\n   >>>   Please select a hatch !   <<<   ")(princ)
			)
		)

	)
)

(princ "\n:: QS_Hatch_Same_Layer&Pattern.lsp | Version 1.1 | by 3Dwannab ::")
(princ "\n:: Type \"QS_Hatch_Same_Layer&Pattern\" OR \"QSH\" to Invoke ::") (princ)

; Some help can be found here that helped me along the way:
; ------------------------------------------------------------
; http://forums.augi.com/showthread.php?163322-Merge-all-hatch-objects-by-pattern-name
; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/get-layer-name-and-colour-from-selected-object/td-p/5697086
; http://forums.augi.com/showthread.php?68534-how-to-select-just-hatch-patterns
; http://www.afralisp.net/visual-lisp/tutorials/properties-methods-part-1.php
; http://www.afralisp.net/visual-lisp/tutorials/properties-methods-part-3.php
; http://www.afralisp.net/visual-lisp/tutorials/properties-methods-part-3.php

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