Modifying Child Label Styles

Modifying Child Label Styles

cfindlay5AYZC
Participant Participant
208 Views
8 Replies
Message 1 of 9

Modifying Child Label Styles

cfindlay5AYZC
Participant
Participant

Our company makes use of many Parent and  Child label styles.

 

I would like the user to be able to select a label, read its name, and swap it for a label with a slightly different name. This would be an individual change only.

 

Retrieving the  'LabelStyle is easy enough ... but it doesn't like it if I try to swap it out for my desired label using ... (vlax-put-property repv 'Labelstyle newrepname) ... it only works if the new label is a Parent label ... 

 

if the name that gets passed to it is a Child Label it cannot be found and I get ... error: Automation Error. The parameter is incorrect

 

Is there a difference between a Parent 'Labelstyle and a Child 'Labelstyle ...

 

Colin (not a .NET guy)

0 Likes
209 Views
8 Replies
Replies (8)
Message 2 of 9

hosneyalaa
Advisor
Advisor

Is there
a code you are working on
that would be better?

0 Likes
Message 3 of 9

cfindlay5AYZC
Participant
Participant

We have a left hand surface spot elevation child label and a corresponding right hand surface spot elevation child label ... basically [L] XXX and [R] XXX.

 

And we want to swap one for the other without requiring any user input.

 

Colin

0 Likes
Message 4 of 9

BlackBox_
Advisor
Advisor

Hey Colin - can you post a sample drawing?

 


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 5 of 9

BlackBox_
Advisor
Advisor

@cfindlay5AYZC - give this a try - it's a modification to one of my own LISP routines for this same task (we only use parent styles), so it now prioritizes child styles then falls back on parent styles: 

 

(vl-load-com)

(defun c:FLIP (/ *error* acDoc ss styleName key newStyleName ok)

  (defun *error* (msg)
    (if ss (vla-delete ss))
    (if acDoc (vla-endundomark acDoc))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )

  (if (ssget "_:L" '((0 . "AECC_*_LABEL")))
    (progn
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
        (setq key
               (substr
                 (setq styleName (vla-get-name (vlax-get x 'LabelStyle)))
                 1
                 3
               )
        )
        (setq newStyleName
                 (vl-string-subst
                   (if (= key "[L]") "[R]" "[L]")
                   key
                   styleName
                 )
          )
        ;; attempt to set child style
        (vlax-for child (vlax-get (vlax-get x 'LabelStyle) 'children)
          (print (vla-get-name child))
          (if (= newStyleName (vla-get-name child))
            (progn
              (vlax-put x 'labelstyle child)
              (setq ok t)
              (prompt
                (strcat "\nChild style \"" newStyleName "\" found. ")
              )
            )
          )
        )
        (if (not ok)
          ;; attempt to set parent style
          (if (vl-catch-all-error-p
                (vl-catch-all-apply
                  'vlax-put
                  (list x
                        'LabelStyle
                        newStyleName
                  )
                )
              )
            (prompt (strcat "\n** \"" newStyleName "\" not found ** "))
            (prompt
              (strcat "\nParent style \"" newStyleName "\" found. ")
            )
          )
        )
      )
    )
  )

  (*error* nil)
)


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 6 of 9

cfindlay5AYZC
Participant
Participant

Code looks sexier than mine for sure but it still isn't able to complete the swap.

 

It can read a child label name, derive the opposite label name, but it cannot replace the old label unless the new label is a parent style. (if the new label name is a child style label it cannot find it and returns an error)

 

Colin

0 Likes
Message 7 of 9

BlackBox_
Advisor
Advisor

@cfindlay5AYZC wrote:

Code looks sexier than mine for sure but it still isn't able to complete the swap.

 

It can read a child label name, derive the opposite label name, but it cannot replace the old label unless the new label is a parent style. (if the new label name is a child style label it cannot find it and returns an error)

 

Colin


It very much swapped to child styles in my drawings. 

 

As I asked before, can you please post a sample drawing?


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 8 of 9

BlackBox_
Advisor
Advisor

@BlackBox_ wrote:


... can you please post a sample drawing?


 

Hey @cfindlay5AYZC - just following up with you on this. 

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 9 of 9

Jeff_M
Consultant
Consultant

@cfindlay5AYZC  I have used code similar to @BlackBox_ and could swap child labelstyles without issue. Note that he uses the actual labelstyle, not the labelstyle name as you were doing. This is likely where the issue is.

Jeff_M, also a frequent Swamper
EESignature