Author Topic: Annotative text - how to access the text object for each scale  (Read 280 times)

0 Members and 1 Guest are viewing this topic.

Prickle Farmer

  • Newt
  • Posts: 26
  • 35+ years of AutoCAD / BricsCAD
Hi All

Below is a snippet of code which does what I want, namely change the insertion point of each different scale of an annotative text object.  There has to be a less "manual" way to do this other than changing the current annotation scale to each scale in turn.

   (command "mtext" p4 "J" "BL" "R" (angtos bg) "S" "OCRE_AN" "H" 2.5 p4 text "")
   (command "objectscale" (entlast) "" "A" "1:200" "1:250" "1:500" "1:2000" "1:5000" "")
   ; go through all the scales and adjust insertion point
   (command "CANNOSCALE" "1:200")
   (setq en (entlast))
   (setq ed (entget en))
   (setq p4 (polar point bg (* off 0.2)))
   (setq ed (subst (cons 10 p4) (assoc 10 ed) ed))
   (entmod ed)
   (entupd en)
   (command "CANNOSCALE" "1:250")
   (setq en (entlast))
   (setq ed (entget en))
   (setq p4 (polar point bg (* off 0.25)))
   (setq ed (subst (cons 10 p4) (assoc 10 ed) ed))
   (entmod ed)
   (entupd en)
   (command "CANNOSCALE" "1:500")
   (setq en (entlast))
   (setq ed (entget en))
   (setq p4 (polar point bg (* off 0.5)))
   (setq ed (subst (cons 10 p4) (assoc 10 ed) ed))
   (entmod ed)
   (entupd en)
etc etc etc for all scales
I'd rather have a bottle in front of me than a frontal lobotomy.

BIGAL

  • Swamp Rat
  • Posts: 818
  • 30 + years of using Autocad
Re: Annotative text - how to access the text object for each scale
« Reply #1 on: July 03, 2021, 07:35:34 PM »
I am not a wiz at annotative stuff but your code can be simplified, sorry not tested but should work

Code: [Select]
(setq lst (list '("1:200" 0.2) '("1:250" 0.25) '("1:500" 0.5) '("1:2000" 2.0) '("1:5000" 5.0)))
   ; go through all the scales and adjust insertion point
  (foreach sc lst
   (command "CANNOSCALE" (nth 0 sc))
   (setq en (entlast))
   (setq ed (entget en))
   (setq p4 (polar point bg (* off (nth 1 sc))))
   (setq ed (subst (cons 10 p4) (assoc 10 ed) ed))
   (entmod ed)
   (entupd en)
   )

A man who never made a mistake never made anything

Prickle Farmer

  • Newt
  • Posts: 26
  • 35+ years of AutoCAD / BricsCAD
Re: Annotative text - how to access the text object for each scale
« Reply #2 on: July 03, 2021, 07:52:18 PM »
Thanks BIGAL.
Creating a list and looping is far more efficient than my "step by step" code.  What I'm hoping is that someone knows how to determine what scales are associated with a text object. In my example I know that the scales are 1:200, 1:250, 1:500, 1:1000 (initial), 1:2000 and 1:5000 because I created the text.  But what if I didn't create the text.  How do I get a list of the anno scales?  There must be a way to access that data without having to change the CANNOSCALE.
I'd rather have a bottle in front of me than a frontal lobotomy.

BIGAL

  • Swamp Rat
  • Posts: 818
  • 30 + years of using Autocad
Re: Annotative text - how to access the text object for each scale
« Reply #3 on: July 04, 2021, 08:55:20 PM »
This is how to find out what scales are attached adding more sorry above my pay rate. Need to add to correct point in data extract look at sc it has the COUNT of how many sub items (vla-item sc x)

Code: [Select]
(defun c:test ()
(setq obj (vlax-ename->vla-object (car  (entsel "Pick obj"))))
(setq sc (vla-item (vla-item (vla-GetExtensionDictionary obj) 0) 0))
(setq x 0)
(repeat (vla-get-count sc)
(setq  hand  (handent (vla-get-handle (vla-item  sc x))))
(setq  e340 (cdr (assoc 340 (entget  hand))))
(princ (strcat "\n" (setq scale (cdr (assoc 300(entget e340))))))
(setq x (1+ x))
)
)

(vlax-dump-object (vla-item  sc 0))
A man who never made a mistake never made anything

Prickle Farmer

  • Newt
  • Posts: 26
  • 35+ years of AutoCAD / BricsCAD
Re: Annotative text - how to access the text object for each scale
« Reply #4 on: July 04, 2021, 09:58:17 PM »
Wow.  Thanks BIGAL.  I can see that drilling down to "sub-entities" (if that is what they are called) gets the stuff I'm interested in.
I have previously used a technique of attaching the handle of an attributed block to the extended entity data of a line so that the line can find data about itself placed anywhere in the drawing.  Seems that internally the drawing database is doing a similar thing, namely using a handle to cross reference another object.  Thanks again BIGAL.  I don't fully understand all of your code (especially vla-item ) but I sure am gonna use it !!
I'd rather have a bottle in front of me than a frontal lobotomy.

BIGAL

  • Swamp Rat
  • Posts: 818
  • 30 + years of using Autocad
Re: Annotative text - how to access the text object for each scale
« Reply #5 on: July 07, 2021, 12:11:09 AM »
A lot of entities will have multiple sub objects hence the Count property, when using vlax-dump-object you often see "Count" so the Vla-item does just that like a list gets items the 1st is 0 not 1. Often something your looking for is in the Count objects.

Should be able to add the scales a add-item method will try to find it may be a get all scales add next then put all back, bit like add a vertice to pline is not a add but a replace using put co-ordinates.

I am not very good at playing with entmod or adding ents, the solution will be using the entmake maybe.
A man who never made a mistake never made anything