Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find scale/angle of existing hatch pattern?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Gordon_S
1162 Views, 8 Replies

Find scale/angle of existing hatch pattern?

I was wondering how to extract the scale and angle of a picked hatch so that I can pass it to a routine that uses the same settings?

--

Gordon

8 REPLIES 8
Message 2 of 9
_Tharwat
in reply to: Gordon_S

Check this out , it would print all dxf codes to the command line .

 

(entget (car (entsel "\n Select an entity :")))

 Tharwat

Message 3 of 9
Kent1Cooper
in reply to: Gordon_S


@Gordon_S wrote:

I was wondering how to extract the scale and angle of a picked hatch so that I can pass it to a routine that uses the same settings?

....


 Here's the Hatch portion of a larger routine of mine that gets various kinds of information from various object types, and sets the appropriate system variables to match.  The 'objtyp' and 'objdata' variables are extracted earlier from the selected entity.

 

   ((= objtyp "HATCH")
      (setvar 'hpname (cdr (assoc 2 objdata))); hatch pattern
      (if (wcmatch (getvar 'hpname) "U,_USER")
        (progn
          (setvar 'hpspace (cdr (assoc 41 objdata))); SPACING [= scale for User-defined pattern]
          (setvar 'hpdouble (cdr (assoc 77 objdata)))
        ); end progn
      ); end if
      (if (/= (getvar 'hpname) "SOLID"); patterns other than Solid
        (progn
          (setvar 'hpscale (cdr (assoc 41 objdata))); SCALE
          (setvar 'hpang (cdr (assoc 52 objdata))); ANGLE
        ); end progn
      ); end if
      (setvar 'hpassoc (cdr (assoc 97 objdata)))
    ); end Hatch object type

Kent Cooper, AIA
Message 4 of 9
pbejse
in reply to: Gordon_S

here's another one

 

(defun c:Hinfo  (/ HatchEnt HAngle Hscale)
      (vl-load-com)
      (cond
            ((and
                   (setq HatchEnt (entsel "\nSelect Hatch Pattern:"))
                   (eq (cdr (assoc 0
                                   (entget (setq HatchEnt
                                                      (car  HatchEnt)))))
                       "HATCH")
                   (setq HatchEnt (vlax-ename->vla-object HatchEnt))
                   (princ (strcat "\nAngle\t"
                                  (rtos (/ (* (setq HAngle (vlax-get-property
                                                    HatchEnt
                                                    "PatternAngle"))
                                              180.0)
                                           pi)
                                        2
                                        2)))
                   (princ (strcat "\nScale\t"
                                  (rtos (setq Hscale (vlax-get-property
                                              HatchEnt
                                              "PatternSpace"))
                                        2
                                        2)))
                   )))
      (princ)
      )

 

 The values for Scale and Angle are stored on Hscale and Hangle variable...

Message 5 of 9
pbejse
in reply to: pbejse

or a shorter one, that is if you dont mind showingthe RAW value

 

(defun c:Hinfo (/ HatchEnt)
      	(vl-load-com)
        (cond ((and
      	(setq HatchEnt (entsel))
      	(eq (cdr (assoc 0 (entget (setq HatchEnt (car HatchEnt))))) "HATCH")
        (setq HatchEnt (vlax-ename->vla-object HatchEnt))
              	(foreach Info '("PatternAngle" "PatternSpace")
		      (princ (strcat "\n" Info	"\t"
                      (rtos (set (setq n (read info)) 
                            (vlax-get-property HatchEnt Info)) 2 2)))
                      
                      )
		)))(princ)
        )

 

 

 

 

modify the list to add more property.

the values would be save as the same name as the poperty i.e.value for angle would be stored in PatternAngle variable

 

Hope this helps

 

 

Message 6 of 9
Gordon_S
in reply to: pbejse

Thanks. I have cobbled together a lisp routine to change the layer etc to match a picked hatch so I can repeat that hatch exactly without having to set everything manually each time, but my routine below doesn't set the layer as desired and I can't work out why. (It is supposed to reset the current layer but it doesn't seem to change for the hatch)

 

(defun c:hatchfrom ()
  (vl-load-com)
  (setq clay (getvar "clayer"))
  (setq x (entsel "\nSelect hatch to repeat: "))
  (command "layer" "S" (cdr (assoc 8 (entget (car x)))) "" )
  (setq pname (vla-get-PatternName (vlax-ename->vla-object (car x))))
  (setq pscal (vla-get-PatternScale (vlax-ename->vla-object (car x))))
  (setq pangl (vla-get-PatternAngle (vlax-ename->vla-object (car x))))
  (setvar "hpassoc" 1)
  (command "-hatch" "P" pname pscal pangl)
  (setvar "clayer" clay)
)

 

If I run the line (command "layer" "S" (cdr (assoc 8 (entget (car (entsel))))) "" ) and pick a hatch, it changes to that layer as expected, but it seems not to as part of this routine.

Message 7 of 9
Gordon_S
in reply to: Gordon_S

On further testing, I'm not sure that any of it works as I thought it might - where have I gone wrong?

Message 8 of 9
Kent1Cooper
in reply to: Gordon_S


@Gordon_S wrote:

On further testing, I'm not sure that any of it works as I thought it might - where have I gone wrong?


It looks like our old friend, the allow-for-finishing-the-command-before-you-go-on-to-reset-the-Layer thing, again....

 

....

  (command "-hatch" "P" pname pscal pangl)

  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar "clayer" clay)

....
 

EDIT:  And another thing:  The PatternAngle property will be returned in radians, so to use it in a Hatch command, you'll need to convert that to degrees.  One advantage of using (setvar 'hpang) for that, and using "" [Enter] to accept the default within the command, is that you don't need to make that conversion.  And you don't need as many variables.  E.g.:

 

(defun c:hatchfrom (/ clay hatchobj)
  (vl-load-com)
  (setq

    clay (getvar 'clayer)
    hatchobj (vlax-ename->vla-object (car (entsel "\nSelect hatch to repeat: ")))

  )
  (setvar 'clayer (vla-get-Layer hatchobj))
  (setvar 'hpname (vla-get-PatternName hatchobj))
  (setvar 'hpscale (vla-get-PatternScale hatchobj))
  (setvar 'hpang (vla-get-PatternAngle hatchobj))
  (setvar 'hpassoc 1)
  (command "-hatch" "P" "" "" "")

  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'clayer clay)
)

Kent Cooper, AIA
Message 9 of 9
Gordon_S
in reply to: Kent1Cooper

Thanks Kent. That works perfectly and will save me quite a bit of time.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost