Adding dimensions to selection set in this AutoLISP code

Adding dimensions to selection set in this AutoLISP code

O_L_2
Explorer Explorer
601 Views
5 Replies
Message 1 of 6

Adding dimensions to selection set in this AutoLISP code

O_L_2
Explorer
Explorer

The code below was taken from this website.

 

I'm happy to find something that can adjust the size of stacked fractions in multiple MTEXT objects. However, it doesn't work for stacked fractions in dimensions. Unfortunately, adding "DIMENSION" to the selection set doesn't seem to work (it just gives me an error). Any idea how to make it work?

 

;; Stack Change  -  Lee Mac
;; Alters the stacking percentage for multiple MText objects.

(defun c:stackchange ( / *error* dm in mt nw pc rx ss st )

   (defun *error* ( msg )
       (if (and (= 'vla-object (type rx)) (not (vlax-object-released-p rx)))
           (vlax-release-object rx)
       )
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   
   (while
       (progn (initget 6)
           (and
               (setq pc (getreal "\nSpecify new stack % (1-100): "))
               (< 100 pc)
           )
       )
       (princ "\nStack % must be less than or equal to 100.")
   )
   (if
       (and pc
           (setq ss
               (ssget "_:L"
                   (list
                      '(0 . "MTEXT")
                      '(1 . "*{*\\S*[#/^]*;}*")
                       (if (= 1 (getvar 'cvport))
                           (cons 410 (getvar 'ctab))
                          '(410 . "Model")
                       )
                   )
               )
           )
       )
       (if (setq rx (vlax-get-or-create-object "vbscript.regexp"))
           (progn
               (vlax-put-property rx 'global     actrue)
               (vlax-put-property rx 'ignorecase actrue)
               (vlax-put-property rx 'multiline  actrue)
               (vlax-put-property rx 'pattern "\\\\H[0-9]+\\.?[0-9]+x;\\\\S([^;]+);")

               (setq dm (getvar 'dimzin))
               (setvar 'dimzin 0)
               (setq nw (strcat "\\H" (rtos (/ pc 100.0) 2 2) "x;\\S$1;"))
               (setvar 'dimzin dm)
                            
               (repeat (setq in (sslength ss))
                   (setq mt (vlax-ename->vla-object (ssname ss (setq in (1- in))))
                         st (vla-get-textstring mt)
                   )
                   (vla-put-textstring mt (vlax-invoke rx 'replace st nw))
               )
               (vlax-release-object rx)
           )
           (princ "\nUnable to interface with RegExp object.")
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

0 Likes
602 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

@O_L_2 wrote:

.... it doesn't work for stacked fractions in dimensions. Unfortunately, adding "DIMENSION" to the selection set doesn't seem to work (it just gives me an error). ....

....
               (ssget "_:L"
                   (list
                      '(0 . "MTEXT")
                      '(1 . "*{*\\S*[#/^]*;}*")
....

What is the error message?  [Never mention getting an error without the specifics.]

 

The issue is surely related to the fact that the 1-code entry for Dimensions with stacked fractions, if they are an aspect of the measured distance and not via text override, is simply (1 . "") -- it only means there's no text override, and does not contain stacked-fraction encoding such as is used in Mtext and filtered for in the code quoted above.

 

There is no way I can think of to filter in selection for only Dimensions that contain stacked fractions [if that's what you're after], since nothing about their entity data will reveal that -- the stacking happens only in generating the Dimension according to its Style, which is where you should look to change that [the DIMTFAC System Variable, the 146 code entry in the Dimension Table definition].  But that would change it in all Dimensions of that Style, not just in selected objects.  Is that acceptable?  And if multiple Styles are used, you would need to do the same in all of them that you want to have their stacked-fraction height changed.

Kent Cooper, AIA
0 Likes
Message 3 of 6

O_L_2
Explorer
Explorer

The error I'm getting is:

Error: ActiveX Server returned the error: unknown name: TextString

 

I realize that it only occurs if I select a dimension with text override. If it's a dimension with no text override, it cannot be added to selection set. (It keeps saying "Select objects: 0 found" when selecting it)

 


@Kent1Cooper wrote:
But that would change it in all Dimensions of that Style, not just in selected objects.  Is that acceptable?  And if multiple Styles are used, you would need to do the same in all of them that you want to have their stacked-fraction height changed.

Yeah, that's not a problem. Ultimately, I want it to work for all the dimensions, and I don't have that many styles with stacked fractions.

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@O_L_2 wrote:

The error I'm getting is:

Error: ActiveX Server returned the error: unknown name: TextString

.....


For a Dimension with a text override, the Property you want to change is not called the same thing as it is for Mext, but is [appropriately] "TextOverride".

Kent Cooper, AIA
0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@O_L_2 wrote:

....

I realize that it only occurs if I select a dimension with text override. If it's a dimension with no text override, it cannot be added to selection set. (It keeps saying "Select objects: 0 found" when selecting it)

....


That's because one without an override doesn't meet the filter criteria.  If you want to be able to select Mtext and Dimensions with or without override, that can be accommodated with a more complex filter list.  But if non-override stacked fractions in Dimensions are all to be fixed, selecting one Dimension object in a given Style is all you need, since the change would not be to Dimension objects but to the Style definition.  Might you want to just force that change in all Dimension Styles, without the need for object selection to include any Dimensions at all?

Kent Cooper, AIA
0 Likes
Message 6 of 6

O_L_2
Explorer
Explorer

Yeah, I think that's not a bad idea, just to cut down the hassle.

0 Likes