Hatchedit only changes one

Hatchedit only changes one

C.Utzinger
Collaborator Collaborator
2,253 Views
33 Replies
Message 1 of 34

Hatchedit only changes one

C.Utzinger
Collaborator
Collaborator

 HI

 

I have the following code, but the Problem is it works only for one hatch. If I select more than one, then only the last selected one changes.

 

What can I do?

 

 

(defun c:<Test5 ( / *error* layr cmd SPIhatch)

	(defun *error* (errmsg)
    	   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      	   (princ (strcat "\nError: " errmsg)))
    	   (setvar 'CLAYER layr)
    	   (setvar 'CMDECHO cmd)
	   (command-s "_.undo" "_end")
    	   (princ "\n"))

;------------------------------------------------

     	(setq layr (getvar 'CLAYER)
              cmd (getvar 'CMDECHO))	
	
	(setq SPIhatch (ssget "I"))

	(if (not SPIhatch)
		 (progn
		   (command "_.undo" "_begin")
		   (setvar 'CMDECHO 0)
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
		   (setvar 'HPNAME "NET")
		   (command "_.-bhatch" "_l" "-I-Schraffur" "_p" "NET" "2" "0" "_a" "_h" "_y" "_a" "_y" "" "_co" "bylayer" "_n" "")
		   (setvar 'CMDECHO 1)
		   (command "_.-bhatch") 
		   (while (> (getvar "cmdactive") 0) (command pause))
		   (setvar 'CLAYER lay)
  		   (setvar 'CMDECHO cmd)
		   (command "_.undo" "_end")
		   (prin1))
		
		 (progn
		   (command "_.undo" "_begin")
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
		   (command "_.-hatchedit" SPIhatch "_p" "NET" "2" "0")
		   (command "_.-hatchedit" SPIhatch "LA" "-I-Schraffur")
		   (setvar 'CLAYER layr)
  		   (setvar 'CMDECHO cmd)
		   (prompt "\nSchraffur angepasst und auf Layer -I-Schraffur gewechselt!")
		   (command "_.undo" "_end")
  		   (princ)) 
	)
) ;_ end of defun

 

0 Likes
Accepted solutions (2)
2,254 Views
33 Replies
Replies (33)
Message 2 of 34

hencoop
Advisor
Advisor

Put the commands in a WHILE loop for the length of the selection set.

(defun c:<Test5 ( / *error* layr cmd SPIhatch)

	(defun *error* (errmsg)
    	   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      	   (princ (strcat "\nError: " errmsg)))
    	   (setvar 'CLAYER layr)
    	   (setvar 'CMDECHO cmd)
	   (command-s "_.undo" "_end")
    	   (princ "\n"))

;------------------------------------------------

     	(setq layr (getvar 'CLAYER)
              cmd (getvar 'CMDECHO))	
	
	(setq SPIhatch (ssget "I"))

	(if (not SPIhatch)
		 (progn
		   (command "_.undo" "_begin")
		   (setvar 'CMDECHO 0)
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
		   (setvar 'HPNAME "NET")
		   (command "_.-bhatch" "_l" "-I-Schraffur" "_p" "NET" "2" "0" "_a" "_h" "_y" "_a" "_y" "" "_co" "bylayer" "_n" "")
		   (setvar 'CMDECHO 1)
		   (command "_.-bhatch") 
		   (while (> (getvar "cmdactive") 0) (command pause))
		   (setvar 'CLAYER lay)
  		   (setvar 'CMDECHO cmd)
		   (command "_.undo" "_end")
		   (prin1))
		
		 (progn
		   (command "_.undo" "_begin")
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
                   (SETQ cnt 0)
                   (WHILE (< cnt (SSLENGTH SPIhatch))
		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "" "_p" "NET" "2" "0")
		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "" "LA" "-I-Schraffur")
                     (SETQ cnt (1+ cnt))
                   )
		   (setvar 'CLAYER layr)
  		   (setvar 'CMDECHO cmd)
		   (prompt "\nSchraffur angepasst und auf Layer -I-Schraffur gewechselt!")
		   (command "_.undo" "_end")
  		   (princ)) 
	)
) ;_ end of defun
AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 3 of 34

C.Utzinger
Collaborator
Collaborator

Sorry but does not work!

0 Likes
Message 4 of 34

hencoop
Advisor
Advisor

what does it do?

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 5 of 34

C.Utzinger
Collaborator
Collaborator

Just the same. Only the last hatch of the selection gets changed.

0 Likes
Message 6 of 34

hencoop
Advisor
Advisor

I'm sorry, bonehead blunder on my part.

I forgot to replace SPIhatch with (SSNAME SPIhatch cnt) ""

I updated my code post... try it now.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 7 of 34

C.Utzinger
Collaborator
Collaborator

Sorry but it doesn't work!

 

Now ist difficult to explain was it does Smiley LOL

 

Only one changes the pattern, but not the layer. And then the Routine stops saying that the pattern is incorrect. Really strange!

 

 

Thank you by the way...

0 Likes
Message 8 of 34

C.Utzinger
Collaborator
Collaborator

Now it works

 

Take away the "" after (SSNAME SPIhatch cnt)!!!

0 Likes
Message 9 of 34

hencoop
Advisor
Advisor

I think the remaining problem is in the command sequence.

step through the command at the command line taking note of each input required.

When you are asked to select the hatch that is where (SSNAME SPIhatch cnt) belongs in your code.

there needs to be a termination of the selection which is "" right after (SSNAME SPIhatch cnt) in the code.

Carefully replicate the required input in your code until you are returned to the command prompt for each command sequence.

I think that will fix it.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 10 of 34

C.Utzinger
Collaborator
Collaborator

This way it works perfect

 

Post the complete code and I accept it as solution.

 

		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "_p" "NET" "2" "0")
		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "LA" "-I-Schraffur")
0 Likes
Message 11 of 34

hencoop
Advisor
Advisor

Good catch!  I use a different setting for the PICK variables than you use.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 12 of 34

hencoop
Advisor
Advisor
Accepted solution

As you requested:

(defun c:<Test5 ( / *error* layr cmd SPIhatch)

	(defun *error* (errmsg)
    	   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      	   (princ (strcat "\nError: " errmsg)))
    	   (setvar 'CLAYER layr)
    	   (setvar 'CMDECHO cmd)
	   (command-s "_.undo" "_end")
    	   (princ "\n"))

;------------------------------------------------

     	(setq layr (getvar 'CLAYER)
              cmd (getvar 'CMDECHO))	
	
	(setq SPIhatch (ssget "I"))

	(if (not SPIhatch)
		 (progn
		   (command "_.undo" "_begin")
		   (setvar 'CMDECHO 0)
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
		   (setvar 'HPNAME "NET")
		   (command "_.-bhatch" "_l" "-I-Schraffur" "_p" "NET" "2" "0" "_a" "_h" "_y" "_a" "_y" "" "_co" "bylayer" "_n" "")
		   (setvar 'CMDECHO 1)
		   (command "_.-bhatch") 
		   (while (> (getvar "cmdactive") 0) (command pause))
		   (setvar 'CLAYER lay)
  		   (setvar 'CMDECHO cmd)
		   (command "_.undo" "_end")
		   (prin1))
		
		 (progn
		   (command "_.undo" "_begin")
  		   (command "_.-LAYER" "_m" "-I-Schraffur" "_co" "8" "-I-Schraffur" "")
                   (SETQ cnt 0)
                   (WHILE (< cnt (SSLENGTH SPIhatch))
		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "_p" "NET" "2" "0")
		     (command "_.-hatchedit" (SSNAME SPIhatch cnt) "LA" "-I-Schraffur")
                     (SETQ cnt (1+ cnt))
                   )
		   (setvar 'CLAYER layr)
  		   (setvar 'CMDECHO cmd)
		   (prompt "\nSchraffur angepasst und auf Layer -I-Schraffur gewechselt!")
		   (command "_.undo" "_end")
  		   (princ)) 
	)
) ;_ end of defun
AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 13 of 34

C.Utzinger
Collaborator
Collaborator

Which Pick variable?

 

I will try, and perhaps fix the correct one in the Routine!

 

Thank you very much!

0 Likes
Message 14 of 34

hencoop
Advisor
Advisor

There is not a "correct" setting.  It is a user preference.  The different settings can change the required command line input when making selections.  All that is necessary is to make the command line input match the current selection sequence.  To make the routine work regardless of the settings you would capture the value of the pick variables that are involved (I would not know which are without experimenting with them) and set them to values that work for your command sequence and then reset them at the end of the program.

 

My current settings are (COMMAND "SETVAR" "?" "PICK*"):

PICKADD 2
PICKAUTO 5
PICKBOX 5
PICKDRAG 2
PICKFIRST 1
PICKSTYLE 1

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 15 of 34

C.Utzinger
Collaborator
Collaborator

I have another Problem with the code.

 

It crashes when you have selected some hatches and an other object (line).

 

I tryed to fix this, but it only works if I only select one object (line):

 

(if (ssget "I" '((0 . "HATCH")))(setq SPIhatch (ssget "I"))(alert "Keine Schraffur gewählt"))

 

Can you help me?

0 Likes
Message 16 of 34

hencoop
Advisor
Advisor

It appears that you do not need to select anything but hatches.  Is that correct?

If so, I can tailor the SSGET function to only allow selection of hatch objects to solve the problem.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 17 of 34

C.Utzinger
Collaborator
Collaborator
Yes i need only to get hatches...

Thank in advance
0 Likes
Message 18 of 34

hencoop
Advisor
Advisor

change this line

 

(setq SPIhatch (ssget "I"))

make it this

 

(setq SPIhatch (ssget "I" '((0 . "HATCH"))))

 Or, this is you want it to prompt you to select them

 

(setq SPIhatch (ssget '((0 . "HATCH"))))

I've got to run.  I'll pick it up tomorrow if you still need some fixing

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
Message 19 of 34

C.Utzinger
Collaborator
Collaborator

HI

 

No, I want to Change them directly without prompt.

 

So with your second code it work fine without braking the Routine:

 

(setq SPIhatch (ssget "I" '((0 . "HATCH"))))

 

Now it would be great if there comes some alert saying that there were other objects than hatches...

 

Can you fix this??? I tried some, but nothing worked...

0 Likes
Message 20 of 34

hencoop
Advisor
Advisor

with this SSGET code:

(setq SPIhatch (ssget "I" '((0 . "HATCH"))))

your selection is filtered to only select the hatches.  It cannot select anything else.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes