Author Topic: Block Entity scale factor data extraction  (Read 2729 times)

0 Members and 1 Guest are viewing this topic.

strebor71

  • Guest
Block Entity scale factor data extraction
« on: March 26, 2015, 08:16:46 PM »
I have been sratching my head over the data I get back from a nentsel operation in a simple routine i am working on. What I need to do is extract the x or y scale factor from a block.  The data I get back doesnt make any sense. for example, I have a series of blocks in a drawing for trees. the blocks are at a scale factor depending on their diameter.  A 20" tree has a factor of 240, a 12" has a factor of 144 etc. what I am trying to do is select a block and have it draw a circle at 7 times the diameter to represent the dripline.  simple right? take the factor divide by 12 to get the diameter and multiply by 7 for the diameter (or 3.5 times for the radius in this case) of the new circle.  that factor is what i am having a problem with. when selecting a 12" (or 144 scale factor) block I get

(<Entity name: 7ffff3e3410> (1868.25 -1049.06 0.0) ((58.6262 -131.526 0.0) (131.526 58.6262 0.0) (0.0 0.0 12.0) (1871.68 -1053.4 0.0)) (<Entity name: 7ffff3def30>))

as a result of the nentsel operation. and attempting to extract the scale factor I get 58.6262?? I have no idea what that number is derived from. below is my code so far. if someone with the knowledge could help explain what i am doing wrong would be sweet.  I have attached a drawing with a few of the tree blocks in it if you need it. but something tells me I just have a simple code mistake.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tf ()
  2.  (repeat 20
  3.   (setq ndata (nentsel "\nSelect a tree block by clicking on its edge: "))
  4.   ((/= ndata nil)
  5.    (setq info (caddr ndata))
  6. (setq sc (ABS (car (nth 0 info))))
  7. (setq inspt (nth 3 info))      
  8. (setq   rad (* 3.5 sc))
  9.     (list '(0 . "circle")
  10.             '(8 . "CL-TDRIP")
  11.             '(6 . "DASHED")
  12.              (cons 10 inspt)
  13.              (cons 40 rad)))
  14.  )
  15.   ((= ndata nil)(alert"  Missed it! Please TRY Again...")(c:tf))
  16.   )
  17. )
  18.   (princ)
  19.   )
  20.  

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Block Entity scale factor data extraction
« Reply #1 on: March 26, 2015, 10:59:51 PM »
Don't use nentsel, use entsel and grab the X or Y scale value ( dxf 41 or 42 ) .. this number will give you your diameter.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Block Entity scale factor data extraction
« Reply #2 on: March 27, 2015, 04:51:17 AM »
I agree with Ron - the transformation matrix returned by nentsel/nentselp gives the transformation between the block definition geometry & the block reference geometry, however, if you are only looking to obtain the block scale factor, simply query the DXF groups 41, 42 & 43, or the ActiveX xscalefactor / yscalefactor / zscalefactor properties (or x/y/zeffectivescalefactor for a dynamic block).

I get 58.6262?? I have no idea what that number is derived from. below is my code so far.

This post may offer some insight.

Lee



ChrisCarlson

  • Guest
Re: Block Entity scale factor data extraction
« Reply #3 on: March 27, 2015, 08:57:26 AM »
Are you doing anything with this data? Wouldn't it be easier to simply have a dynamic block with vis. states for ring On / Off and a scale function with pre-determined increments 12"  , 24", 36" or what have you?

strebor71

  • Guest
Re: Block Entity scale factor data extraction
« Reply #4 on: March 27, 2015, 09:28:50 PM »
Are you doing anything with this data? Wouldn't it be easier to simply have a dynamic block with vis. states for ring On / Off and a scale function with pre-determined increments 12"  , 24", 36" or what have you?
In a perfect world that is how we would have it, but this routine is for adding the drip line to trees in a drawing from a consultant or an old resurrected job prior to having the drip line shown etc., But that is a good idea having it be a dynamic block. Unfortunately we are rarely the ones who actually add the trees to the drawings originally so this helps make due.

Don't use nentsel, use entsel and grab the X or Y scale value ( dxf 41 or 42 ) .. this number will give you your diameter.

so i am having a difficult time getting an association list in order to extract the scale. this is what i got, help!
Code: [Select]
(defun c:tf ()
  (repeat 20
    (setq
      ndata (entsel "\nSelect a tree block by clicking on its edge: ")
    )
    (cond
      ((/= ndata nil)
       (setq sc (/ (cdr (assoc 41 (entget ndata))) 12))
       (setq pt1 (cdr (assoc 10 (entget ndata))))
       (setq rad (* 3.5 sc))
       (entmake
(list '(0 . "circle")
       '(8 . "CL-TDRIP")
       '(6 . "DASHED")
       (cons 10 pt1)
       (cons 40 rad)
)
       )
      )
      ((= ndata nil)
       (alert "  Missed it! Please TRY Again...")
       (c:tf)
      )
    )
  )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Block Entity scale factor data extraction
« Reply #5 on: March 27, 2015, 10:10:00 PM »
Hint .. Use (car (entsel .. Why are you repeating 20 times ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

strebor71

  • Guest
Re: Block Entity scale factor data extraction
« Reply #6 on: March 30, 2015, 07:09:02 PM »
repeating 20 times just so i dont have to run the command each time i need to create the drip line, and there are rarely more that 20 trees. I want to be able to do them one at a time, so doing all at once wont work either. thanks for the hint ill test it out and report.

strebor71

  • Guest
Re: Block Entity scale factor data extraction
« Reply #7 on: March 30, 2015, 08:03:15 PM »
HA!! that did it! works like a charm. Now I just need to figure out how to let it repeat multiple times but also exit cleanly when less than 20. I came up with this for a solution. at least it resets my variables, not sure if it is a good solution or not.

Code: [Select]
(defun c:tf ()
(setq temperr *error*) ;store *error*
(setq *error* trap1) ;re-assign *error*
(setq oldecho (getvar "cmdecho")) ;store variables
(setq osnapset (getvar "OSMODE")) ;saves osnap variables
(setvar "OSMODE" 0) ;turns osnap off for program
(setq units (getvar "LUNITS")) ;GETS CURRENTUNITS
(Setvar "LUNITS" 2) ;SETS UNITS TO  DECIMAL
(setq precision (getvar "LUPREC")) ;saves present precision variable
(setvar "LUPREC" 2) ;sets precision to 2 decimal places for this program
  (repeat 20
    (setq
      ndata (car (entsel "\nSelect a tree block by clicking on its edge: "))
    )
    (cond
      ((/= ndata nil)
       (setq sc (/ (cdr (assoc 41 (entget ndata))) 12))
       (setq pt1 (cdr (assoc 10 (entget ndata))))
       (setq rad (* 3.5 sc))
       (entmake
(list '(0 . "circle")
       '(8 . "CL-TDRIP")
       '(6 . "DASHED")
       (cons 10 pt1)
       (cons 40 rad)
)
       )
      )
      ((= ndata nil)
       (alert "  Missed it! Please TRY Again...")
(SETVAR "LUNITS" units)
(setvar "LUPREC" precision)
(setvar "OSMODE" osnapset)
       (c:tf)
      )
    )
  )
)
  (princ)
 (defun trap1 (errmsg) ;define function
(setvar "cmdecho" oldecho) ;restore variables
  (SETVAR "LUNITS" units)
(setvar "LUPREC" precision)
(setvar "OSMODE" osnapset)
(setq *error* temperr) ;restore *error*
(prompt "\nResetting System Variables ") ;inform user
   (princ)
 )

thanks again for all the help!

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Block Entity scale factor data extraction
« Reply #8 on: March 31, 2015, 03:42:49 AM »
I would suggest something along the lines of:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tf ( / ent enx )
  2.     (while
  3.         (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect a tree block by clicking on its edge: ")))
  4.             (cond
  5.                 (   (= 7 (getvar 'errno))
  6.                     (princ "\nMissed, try again.")
  7.                 )
  8.                 (   (null ent) nil)
  9.                 (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  10.                     (princ "\nSelected object is not a block.")
  11.                 )
  12.                 (   (entmake
  13.                         (list
  14.                            '(0 . "CIRCLE")
  15.                            '(8 . "CL-TDRIP")
  16.                             (if (tblsearch "ltype" "DASHED") '(6 . "DASHED") '(6 . "Continuous"))
  17.                             (assoc  10 enx)
  18.                             (cons   40 (* 3.5 (/ (cdr (assoc 41 enx)) 12.0)))
  19.                             (assoc 210 enx)
  20.                         )
  21.                     )
  22.                 )
  23.                 (   (princ "\nUnable to create circle."))
  24.             )
  25.         )
  26.     )
  27.     (princ)
  28. )

strebor71

  • Guest
Re: Block Entity scale factor data extraction
« Reply #9 on: March 31, 2015, 05:53:58 PM »
WOW! That's humbling. But greatly appreciated. I didnt think of using a while function. what does the value 7 for errno come from? why 7? and what does the association of 210 with enx in the entmake do? Thanks again for the feedback and help.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Block Entity scale factor data extraction
« Reply #10 on: March 31, 2015, 06:15:32 PM »
WOW! That's humbling. But greatly appreciated.

My pleasure  :-)

What does the value 7 for errno come from? why 7?

Please refer to the documentation for the ERRNO system variable.

What does the association of 210 with enx in the entmake do?

This is the extrusion vector (or normal vector) for the plane in which the circle will be constructed; using the DXF group 210 value held by the selected block reference ensures that the circle is constructed in the same plane as the block reference, as opposed to the WCS plane (DXF 210=0,0,1).