linking current dimstyle text size to mtext size

linking current dimstyle text size to mtext size

kenhuse
Contributor Contributor
1,993 Views
30 Replies
Message 1 of 31

linking current dimstyle text size to mtext size

kenhuse
Contributor
Contributor

I have a lisp routine that draws an arc curved leader.

I have added an mtext command at the end.

To start with I would like to have the mtext size match that of the current dimstyle text size.

I should add that within my style dialog box the text size is currently set to 0.00.

Thanks for your help.

 

0 Likes
Accepted solutions (3)
1,994 Views
30 Replies
Replies (30)
Message 2 of 31

hmsilva
Mentor
Mentor

@kenhuse wrote:

I have a lisp routine that draws an arc curved leader.

I have added an mtext command at the end.

To start with I would like to have the mtext size match that of the current dimstyle text size.

I should add that within my style dialog box the text size is currently set to 0.00.

Thanks for your help.


Hello kenhuse and welcome to the Autodesk Community!

 

Please post your code, It will be easier to advise...

 

Henrique

EESignature

0 Likes
Message 3 of 31

kenhuse
Contributor
Contributor
Hello Enrique,

Thanks for your inquiry and help. I did eventually figure it out. Here's
the code with my additions near the bottom in red:

;TIP1292.LSP: AW.LSP Arc Arrow Leader (c)1997
(defun C:AW (/ GAMA BETA ARFA ARCLENG AWIDTH A MIDANGLE ANG)
;--------input endpoints of arc------------------------
(setq os (getvar "osmode"))
(setq TEMPORTHO (getvar "orthomode"))
(setq
TEMPAUNIT (getvar "aunits")
)
(setvar "cmdecho" 0)
(setq TEMPLT (getvar "celtype"))
(setq
TEMPPLW (getvar "plinewid")
)
(setvar "celtype" "bylayer")
(setvar "orthomode" 0)
(setvar "aunits" 0)
(setq PT1 (getpoint "\nStart Point: "))
(setq
PT2 (getpoint PT1 "\nEnd Point: ")
)
(command "arc" PT1 "e" PT2 "d" pause)
;-------calculate start angle and radious of the arc-----
(setq GAMA (getvar "lastangle")) ;arc endpoint tan angle
(setq BETA (angle PT1 PT2))
(setq ARFA (- BETA GAMA))
(setq ARCLENG (distance PT1 PT2))
(setq
RADIOUS (/ (* 0.5 ARCLENG) (sin ARFA))
)
(setq TANANGLE (+ ARFA BETA))
;-------calculate the angle that the midpoint of the
; arrow is on the arc------------------------------
(setq ARWLENG (* (getvar "dimasz") (getvar "dimscale")))
(setq
AWIDTH (/ ARWLENG 3.)
)
(setq SINA (/ (* 0.5 ARWLENG) RADIOUS))
(setq
COSA (sqrt (- 1 (* SINA SINA)))
)
(setq TANA (/ SINA COSA))
(setq A (atan TANA))
(setq MIDANGLE (- TANANGLE A))
(setq
PT3 (polar PT1 MIDANGLE ARWLENG)
) ;arrow end point
(command "erase" "l" "")
(setvar "osmode" 0)

;-----draw pline arc and arrow------------------------------
(setq ANG (* 57.2958 (+ 3.14159 GAMA))) ;pline start angle
(setvar "fillmode" 1)
(command
"pline" PT2 "w" "0" "0" "arc" "d" ANG PT1 "l" "w" "0" AWIDTH
PT3 "w" "0" "0" ""
)
(setvar "orthomode" TEMPORTHO)
(setvar "aunits" TEMPAUNIT)
(setvar "celtype" TEMPLT)
(setvar "plinewid" TEMPPLW)
(setvar "cmdecho" 1)
(setvar "osmode" os)
(setq R (getvar "dimscale"))
(setq S (getvar "dimtxt"))
(setq MTH (* R S))
(setq TEMPLAY (getvar "clayer"))
(command "-layer" "s" "pen2" "")
(command "mtext" pause "H" MTH pause)
(setvar "clayer" TEMPLAY)
(princ)

) ;end aw
(prompt "\nType AW to draw arc leader")
(princ)

Thanks again for responding. Very much appreciated. I will be submitting
other questions I have when I can get to them, Ken
0 Likes
Message 4 of 31

hmsilva
Mentor
Mentor
Hi Ken!
Good to hear it is solved...

Henrique

EESignature

0 Likes
Message 5 of 31

kenhuse
Contributor
Contributor

Hi Henrique,

I have another issue. Our esteemed organization has a policy of exploding dimensions. In order to find the dimstyle I need to make current, I select a bit of text and look to see it's height. I then go to the dimstyle dialog box to select the proper dimstyle.

Do you suppose I could put together a lisp routine that would make current the proper dimstyle after having selected a piece of text?

This would make for a more efficient work session as it is something I commonly have to do.

Thanks Henrique for any help you can provide, Ken

0 Likes
Message 6 of 31

hmsilva
Mentor
Mentor

@kenhuse wrote:

Hi Henrique,

I have another issue. Our esteemed organization has a policy of exploding dimensions. In order to find the dimstyle I need to make current, I select a bit of text and look to see it's height. I then go to the dimstyle dialog box to select the proper dimstyle.

Do you suppose I could put together a lisp routine that would make current the proper dimstyle after having selected a piece of text?

This would make for a more efficient work session as it is something I commonly have to do.

Thanks Henrique for any help you can provide, Ken


Hi Ken,

I will not comment on the 'Our esteemed organization has a policy of exploding dimensions.'

Quick and dirty...

 

(defun c:demo (/ dimstyles dimsty ht lst styl txt)

    (defun dimstyles (/ dimstyle-lst dimstyle-name dimstyle-text-font dimstyle-text-height dimstyle-text-style lst)
        (while (setq dimstyle-lst (tblnext "dimstyle" (null dimstyle-lst)))
            (setq dimstyle-name
                     (cdr (assoc 2 dimstyle-lst))
                  dimstyle-text-height
                     (cdr (assoc 140 dimstyle-lst))
                  dimstyle-text-style
                     (entget (cdr (assoc 340 dimstyle-lst)))
                  dimstyle-text-font
                     (cdr (assoc 3 dimstyle-text-style))
                  lst (cons (list dimstyle-name dimstyle-text-font dimstyle-text-height) lst)
            )
        )
        lst
    )

    (if (and (setq lst (dimstyles))
             (setq sel (car (entsel "\nSelect dimension text:")))
             (setq txt (entget sel))
             (wcmatch (cdr (assoc 0 txt)) "TEXT,MTEXT")
             (setq styl (cdr (assoc 3 (entget (tblobjname "style" (cdr (assoc 7 txt)))))))
             (setq ht (cdr (assoc 40 txt)))
             (vl-some '(lambda (x)
                           (if (and (eq styl (nth 1 x)) (eq ht (nth 2 x)))
                               (setq dimsty (nth 0 x))
                           )
                       )
                      lst
             )
        )
        (progn
            (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-Acad-Object))))
            (vla-put-activedimstyle adoc (vla-item (vla-get-dimstyles adoc) dimsty))
            (princ (strcat "\nCurrent dimension style \" " dimsty " \""))
        )
        (princ "\nIt was not possible to set current a dimension style from the selected text... ")
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 31

Kent1Cooper
Consultant
Consultant

@kenhuse wrote:

.... In order to find the dimstyle I need to make current, I select a bit of text and look to see it's height. I then go to the dimstyle dialog box to select the proper dimstyle.

Do you suppose I could put together a lisp routine that would make current the proper dimstyle after having selected a piece of text?

...


I would take a somewhat simpler approach [partly simpler because you mention only Text height as a criterion, not Style, but also in not needing to make a list of all Dimension Styles]:

 

(defun C:DSTH (/ txt ht done dsdata); = Dimension Style set by selected Text Height
  (setq
    txt (car (entsel "\nSelect Text for height to find matching Dimension Style: "))
    ht (cdr (assoc 40 (entget txt)))
  ); setq
  (while
    (and
      (not done); haven't found one yet
      (setq dsdata (tblnext "dimstyle" (not dsdata))); there's still another Style to check
    ); and
    (if (equal (* (cdr (assoc 140 dsdata)) (getvar 'dimscale)) ht 1e-4); [edit fuzz factor as desired]
      ;; Dimension text height as used same as that of selected Text
      (progn ; then
        (command "_.dimstyle" "_restore" (cdr (assoc 2 dsdata))); set that Style current
        (setq done T); stop looking
      ); progn
    ); if
  ); while
  (if (not done) (prompt "\nNo matching-height Dimension Style found."))
  (princ)
); defun

 

If you have more than one Style with that text height, it will use the first one it finds.

 

For some reason, it won't let me use (setvar 'dimstyle ...), which is why I used the (command) approach, but if (setvar) works for you, that would be simpler.

 

It could use the usual enhancements [verification on selecting Text, command-echo suppression, etc.].

Kent Cooper, AIA
0 Likes
Message 8 of 31

kenhuse
Contributor
Contributor

Thanks so much! That was quick.

I like you comment about exploding dimensions. It causes alot of grief. I wish it wasn't our policy.

I'm sorry to report your impressive lisp program didn't quite work. Maybe it has to do with our dimension style naming conventions.

It did switch to a different dimstyle but the wrong one. Pretty cool but not quite there yet. What happened was I selected the text, and it should have changed to "1 1/2" = 1'-0" (dimstyle named Simp112), but changed to 1/2"=1'-0" (Simp1-2). If you can bear it and have time, I'll elaborate.

We use a text syle in our dimensions called Simp1. Our dimstyle names are Simp1 for 1" = 1", Simp 1-4 for 1/4" = 1'-0", Simp 112, for 1 1/2" = 1'-0", Simp 3-4 for 3/4" = 1'-0" etc.

So it is my humble guess that the lisp program would have to sort through the various dimstyles available in the dimstyle dialog box and find the dimstyle which has the selected text size, then switch to that dimstyle.

I should possibly add that the dimstyle Simp1 has a text size of .13 and has under the "Use overall scale of" 1.0 (under the Scale for dimension features in the Fit tab of the dimstyle). All the other dimstyles change their text size by changing the  "Use overall scale of" number, i.e. 1/2" = 1'-0" (Simp1-2) has a "Use overall scale of" 2.0 , 1/4" = 1'-0" (Simp1-4) has a "Use overall scale of" 4.0, and so on.

I imagine sorting out this kind of thing might be out of your job description. I hope you're paid well whatever your job description because what you do is really helpful in increasing our efficiency. Thanks again, and I'll completely understand if you don't have time for our little puzzle, Ken

0 Likes
Message 9 of 31

kenhuse
Contributor
Contributor

Henrique,

My mistake, Simp1 is the dimstyle used for 1"=1'-0". My apologies for the confusion.

0 Likes
Message 10 of 31

hmsilva
Mentor
Mentor

@kenhuse wrote:

Henrique,

My mistake, Simp1 is the dimstyle used for 1"=1'-0". My apologies for the confusion.


Hi Ken,

did the 'demo' worked as expected, or not?

If not, and because I'm a metric guy, post a sample dwg with some exploded dimensions and dimstyles.

 

Henrique

EESignature

0 Likes
Message 11 of 31

kenhuse
Contributor
Contributor

 

 

I'm sorry to report your impressive lisp program didn't quite work. Maybe it has to do with our dimension style naming conventions.

It did switch to a different dimstyle but the wrong one. Pretty cool but not quite there yet. What happened was I selected the text, and it should have changed to "1 1/2" = 1'-0" (dimstyle named Simp112), but changed to 1/2"=1'-0" (Simp1-2). If you can bear it and have time, I'll elaborate.

We use a text syle in our dimensions called Simp1. Our dimstyle names are Simp1 for 1" = 1'-0", Simp 1-4 for 1/4" = 1'-0", Simp 112, for 1 1/2" = 1'-0", Simp 3-4 for 3/4" = 1'-0" etc.

So it is my humble guess that the lisp program would have to sort through the various dimstyles available in the dimstyle dialog box and find the dimstyle which has the selected text size, then switch to that dimstyle.

I should possibly add that the dimstyle Simp1 has a text size of .13 and has under the "Use overall scale of" 1.0 (under the Scale for dimension features in the Fit tab of the dimstyle). All the other dimstyles change their text size by changing the  "Use overall scale of" number, i.e. 1/2" = 1'-0" (Simp1-2) has a "Use overall scale of" 2.0 , 1/4" = 1'-0" (Simp1-4) has a "Use overall scale of" 4.0, and so on.

I imagine sorting out this kind of thing might be out of your job description. I hope you're paid well whatever your job description because what you do is really helpful in increasing our efficiency. Thanks again, and I'll completely understand if you don't have time for our little puzzle, Ken

0 Likes
Message 12 of 31

kenhuse
Contributor
Contributor

Henrique,

Here's a drawing to experiment with. Thanks!

0 Likes
Message 13 of 31

hmsilva
Mentor
Mentor
Ken,
I have a deadline to meet today, but tomorrow I'll see what I can do.

Henrique

EESignature

0 Likes
Message 14 of 31

kenhuse
Contributor
Contributor

You're awesome! Thanks for all you've done!

0 Likes
Message 15 of 31

hmsilva
Mentor
Mentor

Ken,

try this modified 'demo'

 

(defun c:demo (/ dimstyles dimsty ht lst sd sel styl txt)

   (defun dimstyles (/ dimstyle-lst dimstyle-name dimstyle-text-height dimstyle-scale dimstyle-text-final-height lst)
      (while (setq dimstyle-lst (tblnext "dimstyle" (null dimstyle-lst)))
         (setq dimstyle-name
                 (cdr (assoc 2 dimstyle-lst))
               dimstyle-text-height
                 (cdr (assoc 140 dimstyle-lst))
               dimstyle-scale
                 (cdr (assoc 40 dimstyle-lst))
               dimstyle-text-final-height
                 (* dimstyle-text-height dimstyle-scale)
               lst (cons (list dimstyle-name dimstyle-text-height dimstyle-scale dimstyle-text-final-height) lst)
         )
      )
      lst
   )

   (if (and (setq lst (dimstyles))
            (setq sel (car (entsel "\nSelect dimension text:")))
            (setq txt (entget sel))
            (wcmatch (cdr (assoc 0 txt)) "TEXT,MTEXT")
            (setq ht (cdr (assoc 40 txt)))
            (vl-some '(lambda (x)
                         (if (eq ht (nth 3 x))
                            (setq dimsty (nth 0 x)
                                  sc     (nth 2 x)
                            )
                         )
                      )
                     lst
            )
       )
      (progn
         (or adoc (setq adoc (vla-get-ActiveDocument (vlax-get-Acad-Object))))
         (vla-put-activedimstyle adoc (vla-item (vla-get-dimstyles adoc) dimsty))
         (setvar 'DIMSCALE sc)
         (princ (strcat "\nCurrent dimension style \" " dimsty " \""))
      )
      (princ "\nIt was not possible to set current a dimension style from the selected text... ")
   )
   (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 16 of 31

kenhuse
Contributor
Contributor

Hi Henrique,

 

Thanks for getting in the modification  in the midst of your deadline.

For some reason it's not recognizing the command prompt "demo".

The command doesn't activate.

I saved the .lsp document after pasting in your code.

I opened a drawing which will automatically download the .lsp file.

No luck. Thanks so much in any event.

0 Likes
Message 17 of 31

hmsilva
Mentor
Mentor

@kenhuse wrote:

Hi Henrique,

 

Thanks for getting in the modification  in the midst of your deadline.

For some reason it's not recognizing the command prompt "demo".

The command doesn't activate.

I saved the .lsp document after pasting in your code.

I opened a drawing which will automatically download the .lsp file.

No luck. Thanks so much in any event.


Try the attached one...

 

Henrique

EESignature

0 Likes
Message 18 of 31

kenhuse
Contributor
Contributor

Thanks, it did make a difference and it recognized "demo" but instead of switching to simp1, it went to the standard dimstyle on the drawing. I tried to purge and delete standard but it won't let me.

I tried it on another drawing and it returned the current dimstyle when it should have returned Simp1.

So varying results.

Quite a challenge this. I have faith. Thanks again. 

0 Likes
Message 19 of 31

hmsilva
Mentor
Mentor

@kenhuse wrote:

Thanks, it did make a difference and it recognized "demo" but instead of switching to simp1, it went to the standard dimstyle on the drawing. I tried to purge and delete standard but it won't let me.

I tried it on another drawing and it returned the current dimstyle when it should have returned Simp1.

So varying results.

Quite a challenge this. I have faith. Thanks again. 


Ken,

in the sample file, the only dimstyle with final text height 0.13, is standard, simp1 has 0.125...

(("SIMP 1-2" 0.13 2.0 0.26)
   ("SIMP1 1-2" 0.13 0.66667 0.0866671)
   ("SIMP1-8" 0.125 8.0 1.0)
   ("SIMP112" 0.13 0.6667 0.086671)
   ("simp3-8" 0.13 2.6667 0.346671)
   ("SIMP20" 0.13 20.0 2.6)
   ("SIMP10" 0.13 10.0 1.3)
   ("SIMP40" 0.13 40.0 5.2)
   ("SIMP6" 0.0216667 0.166667 0.00361111)
   ("SIMP3-4" 0.13 1.333 0.17329)
   ("SIMP3" 0.13 0.3333 0.043329)
   ("simp1-16" 0.13 16.0 2.08)
   ("SIMP1-2" 0.13 2.0 0.26)
   ("simp1-4" 0.13 4.0 0.52)
   ("SIMP1" 0.125 1.0 0.125)
   ("STANDARD" 0.13 1.0 0.13)
)

 

__Dims.PNG

 

those texts should return SIMP1

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 20 of 31

kenhuse
Contributor
Contributor

Thanks Henrique,

We have a bit of a mess to clean up, my apologies. You've done a great job of sorting this out for us.

Hopefully after the cleanup, the .lsp wil work. I'm very impressed with and grateful for your help.

I'll get at it when I get to work this morning and get back to you. Thanks again.

 

0 Likes