How to extract scale from this block?

jtm2020hyo
Collaborator
Collaborator

How to extract scale from this block?

jtm2020hyo
Collaborator
Collaborator

I am trying to extract the scale xyz values from the attached block but always have error, here my code:

 

 

(defun DGpvPosition ( / )
  (if (setq GpvPositionX1 (getpropertyvalue (entlast) "Position/X"))
    (setq GpvPositionX1 (car GpvPositionX1))
    (setq GpvPositionX1 1)
  )
  (if (setq GpvPositionY1 (getpropertyvalue (entlast) "Position/X"))
    (setq GpvPositionY1 (car GpvPositionY1))
    (setq GpvPositionY1 1)
  ) 
  (if (setq GpvPositionZ1 (getpropertyvalue (entlast) "Position/X"))
    (setq GpvPositionZ1 (car GpvPositionZ1))
    (setq GpvPositionZ1 1)
  )  
  (setq GpvPositionXYZ1 (list GpvPositionX1 GpvPositionY1 GpvPositionZ1))
)

 

 

Here are the values:

 

ScaleFactors/X (type: double) (LocalName: Scale X) = Failed to get value
ScaleFactors/Y (type: double) (LocalName: Scale Y) = Failed to get value
ScaleFactors/Z (type: double) (LocalName: Scale Z) = Failed to get value

 

how to extract Scale values for the attached code and if null or error return "1"?

 

 

0 Likes
Reply
298 Views
5 Replies
Replies (5)

paullimapa
Mentor
Mentor

try this method instead:

(setq ob (vlax-ename->vla-object (entlast)))

(if

 (not

  (setq GpvPositionX1

   (if(not(vl-catch-all-error-p(vl-catch-all-apply (function (lambda () (setq val (vla-Get-XScaleFactor ob))))))) val)

  ) ; setq

 ) ; not

 (setq GpvPositionX1 1.0) ; when nil

) ; if

(if

 (not

  (setq GpvPositionY1

   (if(not(vl-catch-all-error-p(vl-catch-all-apply (function (lambda () (setq val (vla-Get-YScaleFactor ob))))))) val)

  ) ; setq

 ) ; not

 (setq GpvPositionY1 1.0) ; when nil

) ; if

(if

 (not

  (setq GpvPositionZ1

   (if(not(vl-catch-all-error-p(vl-catch-all-apply (function (lambda () (setq val (vla-Get-ZScaleFactor ob))))))) val)

  ) ; setq

 ) ; not

 (setq GpvPositionZ1 1.0) ; when nil

) ; if


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

ВeekeeCZ
Consultant
Consultant

Explore these properties. See differences if a block is uniformly scaled (as your example is) or not.

 

BeekeeCZ_0-1667035158254.png

 

BlockTableRecord/BlockScaling
ScaleFactors
ScaleFactors/UniformScale
ScaleFactors/X
ScaleFactors/Y
ScaleFactors/Z

 

 

Also these, to be able to fix your current code.

Position
Position/X
Position/Y
Position/Z

 

Note that (dumallproperties) might fail to get some properties while direct (getpropertyvalue e "Property") does not.

leeminardi
Mentor
Mentor

@ВeekeeCZ, gee,  when I use the block editor as you suggest, I get NO for Scale Uniformly.

leeminardi_0-1667046958774.png

 

When I run this code it indicates a scale of 0.001 for x, y, and z which is consistent with the properties for the block.  What gives?

(setq m (nth 2 (nentsel)))
(setq xscale (distance '(0 0 0) (nth 0 m))
      yscale (distance '(0 0 0) (nth 1 m))
      zscale (distance '(0 0 0) (nth 2 m))
)

 

lee.minardi

ВeekeeCZ
Consultant
Consultant

@leeminardi wrote:

@ВeekeeCZ, gee,  when I use the block editor as you suggest, I get NO for Scale Uniformly.

leeminardi_0-1667046958774.png

 

...


 

I double-checked, and it says "Yes". Don't remember ever having some inconsistencies with this one.

 

@jtm2020hyo 

I would use (getpropertyvalue (car (entsel)) "ScaleFactors") 

This consistently returns a list of scales, no matter whether it's uniformly scaled or not.

paullimapa
Mentor
Mentor

I do like your one shot method of getting all x y & z scale factors as a list...so incorporating your method into my code (which won't crash out if a non-block object is selected) will look like this:

 

(if(not(setq GpvPositionXYZ(if(not(vl-catch-all-error-p(vl-catch-all-apply(function(lambda()(setq val(getpropertyvalue(car(entsel)) "ScaleFactors")))))))val)))
(setq GpvPositionX1 1.0 GpvPositionY1 1.0 GpvPositionZ1 1.0)
(setq GpvPositionX1 (nth 0 GpvPositionXYZ) GpvPositionY1 (nth 1 GpvPositionXYZ) GpvPositionZ1 (nth 2 GpvPositionXYZ))
) ; if

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes