Author Topic: Dimension Text Stuff ...  (Read 9716 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dimension Text Stuff ...
« on: May 26, 2006, 11:52:53 PM »
Some observations related to dealing with Associative dimensions ...

The DimObj.Measurement property is NOT necessarily reflected by the displayed Text.
I have seen innumerable "solutions" to extracting the actual dimension which erroneously use the Measurement property.
 
The 'MText' value actually displayed is buried in the nested entity associated with the -2 key of the anonymous block associated with the 2 key of the "DIMENSION" entity.
By stepping through the nested entitys using ENTNEXT all the entitys 'belonging' to the Dimension can be inspected. The nested entitys may include the LINES, INSERTS, MTEXT, and POINTS which make up a Dimension. Depending on the MText formatting there may be several entrys for MTEXT ; an example would be where "\X" or "\P" formatting is used .. each additional line of text will require an additional entity definition nested in the Dimension.


Figure 01
Result from the Measurement Property
This can be demonstrated with the following code :
Code: [Select]
(SETQ DimEnt      (CAR (ENTSEL "\nSelect dimension :"))
      DimObj      (VLAX-ENAME->VLA-OBJECT DimEnt)
      Measurement (VLAX-GET DimObj 'Measurement)
)

;;Returns->  550.903
Which is NOT the actual displayed Text Value.

Note also the Value of the following properties :
 
Code: [Select]
     
(VLAX-GET DimObj 'TextPrefix)
;;Returns-> ""
     
(VLAX-GET DimObj 'TextSuffix)
;;Returns-> ""
       
(VLAX-GET DimObj 'TextOverride)
;;Returns-> ""
So we write this Code to determine Entity Nesting .. warts and all  :
Code: [Select]
(DEFUN c:UnNest-Dims ()
  (IF (AND (SETQ DimEnt (CAR (ENTSEL "\nSelect dimension :")))
           (SETQ dent (ENTGET DimEnt '("*")))
           (= "DIMENSION" (CDR (ASSOC 0 dent)))
           (SETQ anon_block (CDR (ASSOC 2 dent)))
           (SETQ nested_ent (CDR (ASSOC -2 (TBLSEARCH "BLOCK" anon_block 0))))
      )
    (WHILE (SETQ nested_ent (ENTNEXT nested_ent))
      (SETQ EntityType (CDR (ASSOC 0 (ENTGET nested_ent))))
      (PRINC (STRCAT "\nEntity :" EntityType))
      (IF (= "MTEXT" EntityType)
        (PRINC (STRCAT "  :- " (CDR (ASSOC 1 (ENTGET nested_ent)))))
      )
    )
  )
  (PRINC)
)

Result from the nested Entitys using Figure 01 data:
Command: UnNest-Dims
Select dimension :
Entity :LINE
Entity :LINE
Entity :INSERT
Entity :INSERT
Entity :MTEXT  :-  551
Entity :POINT
Entity :POINT
Entity :POINT
Entity :POINT

Let's try some more to test the code ;
First, Change the displayed Values ..
Code: [Select]
(VLAX-PUT DimObj 'TextPrefix "Prefix ")
(VLAX-PUT DimObj 'TextSuffix " Suffix")

Figure 02
Result
Command: UnNest-Dims
Select dimension :
Entity :LINE
Entity :LINE
Entity :INSERT
Entity :INSERT
Entity :MTEXT  :-  Prefix 551 Suffix
Entity :POINT
Entity :POINT
Entity :POINT

Try some more ;
Change the Suffix ..
Code: [Select]
(VLAX-PUT DimObj 'TextSuffix " NewSuffix\\Xand Additional Text")
Figure 03 Result
Command: UnNest-Dims
Select dimension :
Entity :LINE
Entity :LINE
Entity :INSERT
Entity :INSERT
Entity :MTEXT  :-  NewPrefix 551 NewSuffix
Entity :MTEXT  :-  and Additional Text
Entity :POINT
Entity :POINT
Entity :POINT

Check the Suffix and Prefix
Code: [Select]
(VLAX-GET DimObj 'TextPrefix)
;;Returns->"NewPrefix "

(VLAX-GET DimObj 'TextSUFFIX)
;;Returns-> " NewSuffix\\Xand Additional Text"

(VLAX-GET DimObj 'TextOverride)
;;Returns-> ""
Try once More ;
(VLAX-PUT DimObj 'TextPrefix " NewPrefix\\Pand Additional Prefix ")

Figure 04 Result
Select dimension :
Entity :LINE
Entity :LINE
Entity :INSERT
Entity :INSERT
Entity :MTEXT  :-  NewPrefix\Pand Additional Prefix 941 NewSuffix
Entity :MTEXT  :- and Additional Text
Entity :POINT
Entity :POINT

So, theotetically, we can extract the 'ACTUAL' Displayed Dimension ...
by Grabbing the concattenating the  MText values and removing any part of the prefix and any part of the suffix that are included in the string. { removing any "\\X" and "\\P" formatting first }
.... but it  would get very tedious,
SO, Because Acad adds XData for dimension Overrides, we could try this  ...

Code: [Select]
;; (GetDimText-fromXdata)
(DEFUN GetDimText-fromXdata (/ textValue)
  (AND (SETQ DimEnt (CAR (ENTSEL "\nSelect dimension :")))
       (SETQ acad-dstyle (CADR (ASSOC -3 (ENTGET DimEnt '("ACAD")))))
       (SETQ overrides (MEMBER (CONS 1002 "{") acad-dstyle))
       (SETQ textValue (CDR (ASSOC 1000 overrides)))
  )
  textValue
)


Figure 04 Result 
Command: (GetDimText-fromXdata)
Select dimension :
" NewPrefix\\Pand Additional Prefix <> NewSuffix\\Xand Additional Text" 

Then split the string with something like this ;
Code: [Select]
(setq xdString (GetDimText-fromXdata))
;;-> " NewPrefix\\Pand Additional Prefix <> NewSuffix\\Xand Additional Text"
   
(setq splitposition (vl-string-search "<>" xdString))
 ;;-> 34
 
(setq pre-position (vl-string-subst " " "\\X" (vl-string-trim " "(substr xdString 1 splitposition))))
;;-> " NewPrefix\\Pand Additional Prefix "
 
(setq post-position (vl-string-subst " " "\\X" (vl-string-trim " " (substr xdString (+ splitposition 3)))))
;;-> "NewSuffix and Additional Text"
 


Then Re-Write the UnNest-Dims routine to concatenate the Mtext ;
Code: [Select]
(DEFUN c:UnNest-Dim-Value (/ ReturnValue)
  (IF (AND (SETQ ReturnValue ""
                 DimEnt      (CAR (ENTSEL "\nSelect dimension :"))
           )
           (SETQ dent (ENTGET DimEnt '("*")))
           (= "DIMENSION" (CDR (ASSOC 0 dent)))
           (SETQ anon_block (CDR (ASSOC 2 dent)))
           (SETQ nested_ent (CDR (ASSOC -2 (TBLSEARCH "BLOCK" anon_block 0))))
      )
    (WHILE (SETQ nested_ent (ENTNEXT nested_ent))
      (IF (= "MTEXT" (CDR (ASSOC 0 (ENTGET nested_ent))))
        (SETQ ReturnValue (STRCAT ReturnValue " " (CDR (ASSOC 1 (ENTGET nested_ent)))))
      )
    )
  )
  ReturnValue
)

(setq Concatted-Mtext (c:UnNest-Dim-Value ))
;;->  "  NewPrefix\\Pand Additional Prefix 941 NewSuffix and Additional Text"

Then finally ...
Code: [Select]
  (setq
    dimValue (vl-string-subst "" pre-position Concatted-Mtext)
    dimValue (vl-string-trim " " (vl-string-subst "" post-position dimValue))
  )
 
  ;;-> "941"
  ;;-> Whheeeee !

This then lets us overRide the Text value so that we keep the original value when we stretch the Dimension Node Points.


Code: [Select]
(VLAX-PUT DimObj 'TextOverride (VL-STRING-SUBST dimValue "<>" xdString))
.... and that little line of code seems SO simple .....


Figure 05 Result
Note the 941 dimension, overridden from the Figure 4 data

The current values are now ;
Code: [Select]
(VLAX-GET DimObj 'TextPrefix)
;;-> " NewPrefix\\Pand Additional Prefix "

(VLAX-GET DimObj 'TextSUFFIX)
;;-> " NewSuffix\\Xand Additional Text"

(VLAX-GET DimObj 'TextOverride)
;;-> " NewPrefix\\Pand Additional Prefix 941 NewSuffix\\Xand Additional Text"
So if the Dimension has been Overridden before we start, it's simply a matter of removing the prefix and suffix strings from the Override string and we have the string representing the Dimension Value.

[edit : piccys added ]
« Last Edit: May 27, 2006, 01:21:04 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4088
  • C3D user & customizer
Re: Dimension Text Stuff ...
« Reply #1 on: May 27, 2006, 02:35:17 AM »
Nice analysis, Kerry. But it got me to thinking about this.....does this do what you are showing? In my limited testing I think it might.
Code: [Select]
(SETQ DimEnt      (CAR (ENTSEL "\nSelect dimension :"))
      DimObj      (VLAX-ENAME->VLA-OBJECT DimEnt)
)
;;the test results
(setq test1 (getDimText DimObj))

(vla-put-textprefix DimObj "Prefix1 ")
(vla-put-textsuffix DimObj " suffix1")
(setq test2 (getDimText DimObj))

(vla-put-textoverride DimObj "This is <> override 1")
(setq test3 (getDimText DimObj))

(vla-put-textoverride DimObj "This is override 2")
(setq test4 (getDimText DimObj))

;;the code, returns dotted pair of the actual Dimension, based on precision value,
;; and the actual Mtext text.... NOT tested with Dim's having AltUnits on.
(defun getDimText (DimObj / Measurement MeasurementText override
            position DimText
  )
  (setq Measurement (VLAX-GET DimObj 'Measurement)
MeasurementText (rtos Measurement
      (vla-get-unitsformat DimObj)
      (vla-get-PrimaryUnitsPrecision DimObj)
)
  )
  (cond ((eq (setq override (vla-get-textoverride DimObj)) "")
(setq DimText (strcat (vla-get-textprefix DimObj)
       MeasurementText
       (vla-get-textsuffix DimObj)
       )
)
)
((setq position (vl-string-search "<>" override))
(setq DimText (strcat (substr override 1 position)
       (vla-get-textprefix DimObj)
       MeasurementText
       (vla-get-textsuffix DimObj)
       (substr override (+ position 3))
       )
)
)
(t (setq DimText override))
  )
  (cons MeasurementText DimText)
)


Quote from: TheResults
("551" . "551")
("551" . "Prefix1 551 suffix1")
("551" . "This is Prefix1 551 suffix1 override 1")
("551" . "This is override 2")
« Last Edit: May 27, 2006, 03:14:17 AM by Jeff_M »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Stuff ...
« Reply #2 on: May 27, 2006, 07:31:56 AM »
The solution you show is frustratingly close Jeff.

Using the units and precision globals is going to be correct in the vast majority of cases.
... the glitch comes when the dims in question do not conform to the globals .. a real bummer.

I've even tried extracting the dim dimstyle Name and them mining the DimStyle tables for the current settings, but can't guarantee that the table settigs were used to generate the dim object  in question.

 My notes were a little scrappy, perhaps I should wrap the solution so it's self contained and a little easier to follow.  This is an issue I've been chasing down for a while. I wonder if the NET API provides a more elegant solution ? I'll have a look tomorrow.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

nivuahc

  • Guest
Re: Dimension Text Stuff ...
« Reply #3 on: May 27, 2006, 07:48:27 AM »
Kerry, that was a fantastic and educational write-up and would be a wonderful article on the front page. Any chance you'd be willing to submit it as such?

- Chuck

Jeff_M

  • King Gator
  • Posts: 4088
  • C3D user & customizer
Re: Dimension Text Stuff ...
« Reply #4 on: May 27, 2006, 02:04:40 PM »
The solution you show is frustratingly close Jeff.

Using the units and precision globals is going to be correct in the vast majority of cases.
... the glitch comes when the dims in question do not conform to the globals .. a real bummer.
Kerry, those are not globals....they are unique to each DimObject. In my test Dim, for example, I tested it both immediately after creating the dimension, thereby it was using the DimStyle setting, and then agian after I adjusted the Dim's PrimaryUnitsPrecision. Both times the correct result is returned.

Could you post or send me a drawing showing how yours works and mine doesn't? I am really curious as to what could be changing the Mtext value that I didn't cover.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Stuff ...
« Reply #5 on: May 27, 2006, 06:48:23 PM »
........ Kerry, those are not globals....they are unique to each DimObject. ...... 

 :oops:

Well, colour me red, so they are .. cause you're getting the values from the DimObj .. and now that I look at the object properties there they are. Appears I haven't been able to see the woods for the trees.

 Ill have a look and rethink my approach. That will sure make my life easier.

Thanks Jeff, thats brilliant.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dimension Text Stuff ...
« Reply #6 on: May 27, 2006, 08:24:31 PM »
I've made a small change Jeff
testing override for both "" and "<>"
Code: [Select]
........
    (setq override (vla-get-textoverride DimObj))
    (cond ((or (eq override "")
               (eq override "<>")
           )
           (setq DimText  ........

For anyone who wonders why we want to change the text value of assoc' dims but leave the correct <original> dimension there when we stretch the dims, have a look at the piccy.
The steel shaft measures 12745 long, but we have to fit it onto a 7900 border <ISO A1 scaled at 1:10> and maintain the general detail of 1:10 and retain the convenience of dimensions that 'stick' together.. so we stretch down the member after dimensioning at the correct scale.

We then have to be able to extract the "correct" dimension distance from the overridden text programatically. Sometimes additional notation is made with prefix and suffix before the text is overridden.
The real problem rears its head when the displayed override was not generated from the prefix and suffix concatenated with the Length Text.  Once the text is overridden the prefix and suffix are no longer represented as text, though they are retained as properties. It's pretty hard to isolate the "REAL DIMension" from the overridden text string if the suffix and prefix values are not included in the string.
« Last Edit: May 27, 2006, 08:33:48 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hermanm

  • Guest
Re: Dimension Text Stuff ...
« Reply #7 on: December 07, 2010, 09:46:16 PM »
Just saw this old thread.

My solution is similar to Jeff's post, in that it constructs the override text from the measured value, & checks for style-dependent prefix/suffix & any other existing override strings.

Since we use arch units @ 1/16" precision exclusively & this routine is intended for internal use, the override string is built by extracting the measured value & converting with (rtos <measured value> 4 4). We remove inch marks and the fraction bar, as is usual for structural steel shop dwgs in the U.S.

The routine also does the following:

1. Overrides the DimensionLineColor to indicate distorted lengths.
For Ordinate dimensions, this must be ExtensionLineColor instead.

2. Stores the measured value as ldata, as well as an indicator that the length has been distorted.

3. Stores override prefix/suffix text as ldata.

4. Provides an "inverse" function, which restores associativity, along with prefix/suffix text overrides, using the stored ldata.

Note: the "inverse" function does not change the definition points, only restores associativity.

xiaxiang

  • Guest
Re: Dimension Text Stuff ...
« Reply #8 on: December 08, 2010, 03:29:21 AM »
Herman,thank you for sharing. :roll:

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dimension Text Stuff ...
« Reply #9 on: December 08, 2010, 07:15:07 PM »
check out:
;;;Tip1566A:  DIMNOTE.LSP   Dimension Notes   (c)1999, Mike Lapinski
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dimension Text Stuff ...
« Reply #10 on: December 08, 2010, 07:18:33 PM »
and:

;; www.geometricad.com
;|
8:04 AM 6/22/2004
www.geometricad.com

NEW

Command: STICKTO-DIM - Copyright (C)2004-2005-2006 by Luis Esquivel

This command will stick auxiliary lines over the extension and dimension line
To allow the possibility to change individually the properties of a dimension
object to suit.

i.e.- To mark center lines for dimension lines.

Note:
The following dimension system variables are modified inside of the STICKTO
command in order to work the reactor.

dimtih = 0
dimtoh = 0
dimtad = 1

--------------------------------

Steps:

1. Draw a linear dimension object ie: DIMLINEAR, DIMROTATED...

2. Run the command STICKTO-DIM and follow the prompts.

3. Now modify the linetype for one of the extensions to ie: CENTER2.

4. Now do any modification to the dimension and see how the line stick to it.

5. If the dimension object is being erase, it will delete the dimension including
   the stickied lines.

7. If any of the stickied lines is being erase from the dimension, the dimension will
   remain and the rest of the stickied lines also, but the reactor will be lost, you must
   delete the others stickied lines.

8. Dimensions selected via STICKTO-DIM are by default turn off the extensions lines,
   make sure you kept the extension lines off,

--------------------------------

Remember: This software is provided "AS-IS" no support et-al, use it at your own risk.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

LE3

  • Guest
Re: Dimension Text Stuff ...
« Reply #11 on: December 08, 2010, 07:39:52 PM »
^
wow.... i remember those days....

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dimension Text Stuff ...
« Reply #12 on: December 08, 2010, 07:57:37 PM »
^
wow.... i remember those days....

"as is days"  LOL
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

xiaxiang

  • Guest
Re: Dimension Text Stuff ...
« Reply #13 on: December 08, 2010, 10:12:29 PM »
and:
;; www.geometricad.com
;|
8:04 AM 6/22/2004
www.geometricad.com
NEW
Command: STICKTO-DIM - Copyright (C)2004-2005-2006 by Luis Esquivel
Sorry, but the link is broken.And how can I find "Tip1566A: DIMNOTE.LSP Dimension Notes (c)1999, Mike Lapinski "?
Can you upload these two routines for me? Thanks :?

LE3

  • Guest
Re: Dimension Text Stuff ...
« Reply #14 on: December 08, 2010, 10:35:38 PM »