Jump to content

Recommended Posts

Posted

Hello .

 

I am trying to get the width of the Dimension Text with the following codes , but it seems that it's refused to give it to me .:lol:

 

I did convert the vla-object to Autolisp entity to get it because I couldn't find the Vlisp function which could bring the Dimension text Width .

 

So what is your suggestion ?

 

 
(vl-load-com)
(if (setq ss (ssget '((0 . "DIMENSION"))))
 (progn
   (setq sset (ssname ss 0))
   (setq ent (vlax-vla-object->ename (vlax-ename->vla-object sset)))
   (setq wid (cdr (assoc 42 (entget ent))))
                                       ; => This DXF supposed to give the Horizontal width of the characters but it does not .
 )
 (princ)
)

Great thanks.

 

Tharwat

Posted

Example:

 

(defun LM:GetDimensionMText ( dim / db )
 (if
   (and
     (wcmatch (cdr (assoc 0 (entget dim))) "*DIMENSION")
     (setq db (tblobjname "BLOCK" (cdr (assoc 2 (entget dim)))))
   )
   (while (and (setq db (entnext db)) (not (eq "MTEXT" (cdr (assoc 0 (entget db)))))))
 )
 db
)


(defun c:test ( / e m )
 (if
   (and
     (setq e (car (entsel)))
     (wcmatch (cdr (assoc 0 (entget e))) "*DIMENSION")
     (setq m (LM:GetDimensionMText e))
   )
   (princ (strcat "\nWidth: " (rtos (cdr (assoc 42 (entget m))))))
 )
 (princ)
)

Posted

By the way, this:

 

 (setq ent (vlax-vla-object->ename (vlax-ename->vla-object sset)))

 

Is completely redundant since you are converting the Entity Name to a VLA-Object, then back to an Entity.

Posted

Great example.

 

It seems that the dimension has a block definition due to the use of tblobjname and entnext in your routine .:) Correct ?

 

Is there a Vl function to get the Dim. text width ?

 

I looked for it but I couldn't come up with anyone.

 

Thank you.

Posted
It seems that the dimension has a block definition due to the use of tblobjname and entnext in your routine .:) Correct ?

 

Correct, an anonymous block.

 

Is there a Vl function to get the Dim. text width ?

 

I tend to use Vanilla AutoLISP for this task, does it necessarily need to be Visual LISP?

Posted

Because when trying to extract the needed codes in VL , it is recommended to continue in VL not to jump form VL to Lisp and back to VL .

 

That's it only .

Posted

When using the function vlax-dump-object to extract an entity of a dimension , I couldn't find the width of dimension text among them .

 

Any other extraction way ?

 

Thanks

Posted
When using the function vlax-dump-object to extract an entity of a dimension , I couldn't find the width of dimension text among them .

 

The width will be associated with the Dimension MText Object which resides in the anonymous block definition for the dimension. I don't think you can access the anonymous block name using Visual LISP however.

 

Again I would question why this has to be accomplished using Visual LISP? Are you intending to use the code with ObjectDBX? (Even then, most ent* methods still work).

Posted

I do not have plans to deal with ObjectDBX at the moment but maybe in the near future .:)

 

And in regard to the accomplishments , actually I have nothing in-particular to do with it , but I have been wondering why can't I find the VL function that belong to Dimension Text Width among the Property values and Methods supported that belong to the dimension entity.

 

So as you said I can't access Block definition by VL and we should stick with dxf to handle this issue and extract the needed information as well .

 

Thanks a lot.

Posted

Here's a weird way of doing that

 

We know that dimension text reference a particular textstyle, what i'm thinking was if the dimension doesnt contain override properties it means text width is the textsyle width

and if there are overrides, check for the width escape code

 

(defun c:DimWidth  (/ DimTExt WidthOverideDimStr)
     (vl-load-com)
     (setq DimText (car (entsel "\nSelect Dimension:")))
     (eq (cdr (assoc 0 (entget Dimtext))) "DIMENSION")
     (setq DimText (vlax-ename->vla-object DimText))
     (wcmatch (vla-get-TextOverride DimText) "*\\W*")
     (print
           (if (setq WidthOveride
                          (vl-string-search
                                "[url="file://\\W"]\\W[/url]"
                                (setq DimStr
                                           (vla-get-TextOverride
                                                 DimText))))
                 (distof (substr DimStr
                                 (+ 3 WidthOveride)
                                 (- (vl-string-search
                                          ";"
                                          DimStr
                                          WidthOveride)
                                    (+ 2 WidthOveride))))
                 (cdr (assoc 41
                             (tblsearch
                                   "STYLE"
                                   (vla-get-TextStyle DimText))))
                 )
           )
     (princ)
     )

Posted

Thanks pBe .

 

That would return the Text Style Width at either Override Property or not .

 

Many thanks .

Posted
Here's a weird way of doing that

 

What about the Dimension Value itself? You would need to consider Dimension value precision, the Dimension Prefix and/or Suffix, also that the Dimension Text can contain a whole lot of MText formatting codes.

Posted
What about the Dimension Value itself? You would need to consider Dimension value precision, the Dimension Prefix and/or Suffix, also that the Dimension Text can contain a whole lot of MText formatting codes.

 

I never did found out how to that with VL, I stopped looking for that from the time you provided one for DXF :) (i always believe in "not reinventing the wheel")

 

Remember this?

 
(defun LM:GetDimensionString ( dim / dl db ds )
 (if
   (and
     (wcmatch (cdr (assoc 0 (setq dl (entget (ssname js 0))))) "*DIMENSION")
     (setq db (tblobjname "BLOCK" (cdr (assoc 2 dl))))
   )
   (while (and (setq db (entnext db)) (not ds))
     (if (eq "MTEXT" (cdr (assoc 0 (setq dl (entget db)))))
       (setq ds (cdr (assoc 1 dl)))
     )
   )
 )
 ds
)

 

Out of curiosity, thought i try VL with width values, the first thing that pops into my mind is TEXTSTYLE, since textstyle is listed on VL properties. (cheater huh?) :lol:

Posted
i always believe in "not reinventing the wheel"

 

Exactly. Some things are easier to do using Visual LISP, whilst others are far easier using Vanilla AutoLISP. I really don't understand the obsession some members of this forum have with using Visual LISP, when, for many cases, the use of Vanilla can be both easier, more concise, and is almost always faster.

Posted
Exactly. Some things are easier to do using Visual LISP, whilst others are far easier using Vanilla AutoLISP. I really don't understand the obsession some members of this forum have with using Visual LISP, when, for many cases, the use of Vanilla can be both easier, more concise, and is almost always faster.

 

My thoughts exactly.

 

Cheers Lee Mac :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...