Author Topic: A hatch'n Lisp  (Read 6046 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Guest
A hatch'n Lisp
« on: March 15, 2005, 10:36:43 AM »
Good morn'n all,  Hope yer hav'n a great week.

Question, does anyone know of a variable or association of some sort to select all hatch in a dwg, all at once.

I get dwgs from others often and many times they have detail in their plans that are of no use to my work.  The problem I am having is that most of their hatching is associated and in pieces and is really time consuming to select one at a time with the HE (hatchedit) command to disassociate it.  I am in the mood to write a lisp that will select all the hatch in the dwg and disassociate it.  I would also like to write a reciprocol to that so it will select all hatch and associate it as well.

Any ideas would be greatly appreciated.
Thanks.

whdjr

  • Guest
A hatch'n Lisp
« Reply #1 on: March 15, 2005, 10:47:11 AM »
Try this:
Code: [Select]
(ssget "X" '((0 . "HATCH"))) to select the hatches

Code: [Select]
(command "ERASE" (ssget "X" '((0 . "HATCH"))) "") to erase all hatches.

daron

  • Guest
A hatch'n Lisp
« Reply #2 on: March 15, 2005, 10:53:23 AM »
You might want to make sure all hatches are disassociated before erasing them though.

Hangman

  • Guest
A hatch'n Lisp
« Reply #3 on: March 15, 2005, 12:47:23 PM »
Exactly Daron !!!

Thank you whdjr (so how do you pronounce that anyway ???).  :)

I believe I have the disassociation under control (I think), shouldn't be too bad.
It's the association I have in question, how can I re-associate a hatch after it's been disassociated ???  Without reselecting the border and redoing the hatch.

ronjonp

  • Needs a day job
  • Posts: 7526
A hatch'n Lisp
« Reply #4 on: March 15, 2005, 12:56:19 PM »
Quote
It's the association I have in question, how can I re-associate a hatch after it's been disassociated ??? Without reselecting the border and redoing the hatch.


If the hatch has been exploded you can't (to my knowledge)...if it doesn't have a boundary, do a search for hatchb.lsp. you will still have to recreate it to become associative again though....

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Hangman

  • Guest
A hatch'n Lisp
« Reply #5 on: March 15, 2005, 01:14:58 PM »
Ok Ron, that makes sense.  But if the hatch has been mearly disassociated, still has the border, nothing else has been done or moved, couldn't it be reassociated ???

K guys, let me pick you brain a bit, looking at whdjr's code,
Quote
Code:
(ssget "X" '((0 . "HATCH")))

I understand the X is for selecting everything in the database.  Can you tell me what the foot mark ( ' ) is for, and why the two sets of parenthesis ???
Also, the zero, period and then the quoted "hatch", although I understand the quoted "hatch", the filter for the ssget to find just the hatch, correct ???  But what is the zero, space and period for ???

I tried this but for some reason, it's selecting only one hatch pattern.  I created four quick boxes, placed four different associated hatch patterns in these boxes and tried this code.  Any ideas ???

daron

  • Guest
A hatch'n Lisp
« Reply #6 on: March 15, 2005, 01:25:45 PM »
(list (cons 0 "HATCH"))

'((0 . "HATCH"))

are essentially the same thing. The difference is this: (list ...) will pass info from a variable and '((...)) will read it as is.
Example:
(setq brink "disaster")
(list (cons 1 brink))
return: (1 . "disaster")
'((1 . brink))
return: (1 . brink) if it even gets that far. It may just say it can't do it. Look up quote in the developer help. That is what is happening as far as I know.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
A hatch'n Lisp
« Reply #7 on: March 15, 2005, 01:28:36 PM »
What makes you think it's only selecting one hatch?

Back to the other questions....When providing data for filters you must pass it in entity lists, or dotted pairs. When you (entget) an entity, you see a list of dotted pairs.....we are merely passing those of interest to the SS filter. So we want to filter for objects with Entity Type (assoc code 0) "Hatch", we need to pass the dotted pair of (0 . "HATCH"). Now the filter list is a list of lists (a dotted pair is a specila kind of list) since we could filter for the layer, too. '((0 . "HATCH")(8 . "MYLAYER")). The quote symbol ' is used to say "this is a quoted list, use it just as it is written". But what if we had asked the user for the entity type? Now that type is in a variable "eType".....in order to use a variable in a list, it can no longer be quoted so we would use this form: (list (cons 0 etype))

Does that help clear it up?

ronjonp

  • Needs a day job
  • Posts: 7526
A hatch'n Lisp
« Reply #8 on: March 15, 2005, 01:33:31 PM »
The 0 is the dxf code that holds the entity name.

Code: [Select]
Command: dxflist

Select entity to display its data:
(-1 . <Entity name: 7433de08>)
(0 . "HATCH")
(330 . <Entity name: 754cecf8>)
(5 . "3D31")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "hatch")
(100 . "AcDbHatch")
(10 0.0 0.0 0.0)
(210 0.0 0.0 1.0)
(2 . "ANSI31")



I use this lisp routine to display an object DXF data:

Code: [Select]
(defun c:dxflist (/ cmdeko en1 en2 nlay nlay2)
   (setq cmdeko (getvar "cmdecho"))
   (setvar "cmdecho" 0)
   (setq en1 (entsel"\nselect entity to display its data: "))
   (setq en2 (entget (car en1) '("*")))
   (setq nlay (assoc 8 en2))
   (setq nlay2 (cdr nlay))
   (textscr)
   (list en2)
   (foreach n en2 (print n))
   (setvar "cmdecho" cmdeko)
   (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Hangman

  • Guest
A hatch'n Lisp
« Reply #9 on: March 15, 2005, 01:47:43 PM »
Jeff, I know it only selected one because,
I ran the -hatchedit command at the command prompt, when it asked to select the hatch pattern, I typed in the code:
(ssget "X" '((0 . "hatch")))
I then watched one hatch pattern get selected.  I then typed the D for dissassociate and it did just that.  Then I checked the four boxes, three were still associated and one, the one that was initially selected was disassociated.

Thanks for the info.
So, in other words, this is listing the hatch's that I have in the dwg.  I then need to setq those hatch's and then disassociate, correct ???

Maybe I'm in over my head here.  I'm thinking I understand but perhaps I am not.  What do you think ???

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
A hatch'n Lisp
« Reply #10 on: March 15, 2005, 02:16:26 PM »
Ah HA! Hangman, the (ssget "x" '((0 . "HATCH"))) is not what is failing you.....all of the hatches ARE selected. It is the hatchedit command...it only allows one hatch to be selected, so when you pass it the selection set it only uses the first one in it........

So something like this will work:
Code: [Select]

(defun c:unassoc (/ ss count)
  (if (setq ss (ssget "X" '((0 . "HATCH"))))
    (progn
      (setq count 0)
      (repeat (sslength ss)
(command "-hatchedit" (ssname ss count) "d")
(setq count (1+ count))
)
      )
    )
  (princ)
  )

daron

  • Guest
A hatch'n Lisp
« Reply #11 on: March 15, 2005, 02:24:50 PM »
Or this:
Code: [Select]
(defun c:hd (/ ss cnt hash)
     (setq ss (ssget->vla-list (ssget '((0 . "hatch"))))
  cnt 0
  hash (vl-list-length ss))
     (mapcar '(lambda (x)
  (cond ((= (vla-get-associativehatch x) :vlax-true)
 (vla-put-associativehatch x :vlax-false)
 (setq cnt (1+ cnt))
 )
)
  )
    ss
    )
     (mapcar 'vlax-release-object ss)
     (princ)
)


Of course, you need to get se7en's ssget->vla-list procedure for it to work. I know it can be found somewhere on the swamp.

Hangman

  • Guest
A hatch'n Lisp
« Reply #12 on: March 15, 2005, 05:17:41 PM »
Jeff,  Thanks,  I forgot that the hatchedit command limits itself to one selection at a time.  I started trying to figure out how to do a count so that the command would repeat itself until ALL the hatch was diassociated.

Daron,  I appreciate your post.  I've been trying to learn that coding but I've got a long way to go.  I have another lisp I'm working on that requires VB and I'm at a loss at the moment.

Thanks guys.

Do any of you have any idea about reassociating a hatch ???   I've read somewhere (I don't believe it was at the swamp) about the possibility but the hatch would have to have been a recently disassociated hatch and no border or outline having been moved.