TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pmvliet on January 03, 2006, 05:14:53 PM

Title: Hatch selection
Post by: pmvliet on January 03, 2006, 05:14:53 PM
Hey everyone...

I'm gonna try and muddle thru and create a routine. We routinely do a lot of solid hatching with linework for either color elevations, presentations, floor patterning etc. I want to create a lisp routine that will scan the drawing for all solid hatching,
start draworder and send it to back.

From reading a little SSGET seems to be what I want? (SSGET "X") selects the entire drawing database. So I need
to add a filter list to give me just the hatch pattern of solid. The following will get me all hatches:
Code: [Select]
(DEFUN C:SOLIDBACK (/ SS2)
  (setq ss2 (ssget "X"
   '((0 . "HATCH"))
    )
  )
)

switching (0."hatch") to (2."solid) using the dxf group codes doesn't work...

what would be my other options?

Pieter


Title: Re: Hatch selection
Post by: T.Willey on January 03, 2006, 05:18:11 PM
This just worked for me.
(ssget '((0 . "HATCH")(2 . "SOLID")))

Does it not work for you?  You can change it so that it selects all objects.
Title: Re: Hatch selection
Post by: deegeecees on January 03, 2006, 05:44:54 PM
Not tested yet:

Code: [Select]
(defun c:bh_2back (/bh_ents)
(setq bh_ents (ssget '((0 . "HATCH")(2 . "SOLID"))))
(command "draworder" bh_ents "b")
(princ)
)

 :-)
Title: Re: Hatch selection
Post by: ronjonp on January 03, 2006, 06:26:54 PM
Try this.....might give you some ideas:

Code: [Select]
(defun c:shb (/ ss)
  (if (setq ss (ssget "x" '((0 . "HATCH") (2 . "SOLID"))))
    (command ".draworder" ss "" "back")
    (alert "\n No solid hatches found!")
  )
  (princ)
)

Ron
Title: Re: Hatch selection
Post by: pmvliet on January 03, 2006, 06:39:26 PM
So I can link (0."hatch") and (2."solid") together? kewl...  :-D

ok, so I understand everything, what does  ` <<---- do in the code for ssget?

Thanks,
I'll be adding to this... I'm gonna use your codes as reference...

Pieter
Title: Re: Hatch selection
Post by: T.Willey on January 03, 2006, 06:46:30 PM
ok, so I understand everything, what does ` <<---- do in the code for ssget?

From my understanding.
The ' marks tell Acad to interpret what follows as it is.  That is why when you have a varialbe, you have to use list instead of '.

ie.
Code: [Select]
(ssget '((0 . "hatch") (2 . "solid")))
is the same as
Code: [Select]
(setq ObjType "hatch" PatName "solid)
(ssget (list (cons 0 ObjType) (cons 2 PatName)))
but you could not use
Code: [Select]
(setq ObjType "hatch" PatName "solid)
(ssget '((0 . ObjType) (2 . PatName)))
because it would interpret the variable ObjType as the type of object you are looking for.

Hope that clears things up a little.
Title: Re: Hatch selection
Post by: pmvliet on January 03, 2006, 07:35:47 PM
ok....
Got it to work. Maybe I had another typo, but it seems that to put this into an IF statement the "X"
needs to be there...

last question about this
Code: [Select]
(princ)I've seen this in lots of code, but what does it do... I know silly question but for the code I write, I want to understand.
I just don't see any difference at the command line.

Thanks
Title: Re: Hatch selection
Post by: Jeff_M on January 04, 2006, 12:29:55 AM
All lisp routines will return the last evaluated expression....so based on the help file's description for Exiting Quietly:
Quote
Exiting Quietly
If you invoke the princ function without passing an expression to it, it displays nothing and has no value to return. So if you write an AutoLISP expression that ends with a call to princ without any arguments, the ending nil is suppressed (because it has nothing to return). This practice is called exiting quietly.
Title: Re: Hatch selection
Post by: Jürg Menzi on January 04, 2006, 11:23:54 AM
In addition to Tim's replay... You can also mix between cons and quoted:
Code: [Select]
(setq PatName "SOLID")
(list '(0 . "HATCH") (cons 2 PatName))
Title: Re: Hatch selection
Post by: pmvliet on January 04, 2006, 05:17:17 PM
Thanks Everyone!

I learned a little... now for my next routine...

Pieter