Rename a dimstyle

Discussion in 'AutoCAD' started by Jamie Duncan \(remove lock to reply\), Apr 16, 2004.

  1. Is this possible? in lisp? or vlisp?



    --


    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan \(remove lock to reply\), Apr 16, 2004
    #1
  2. Jamie Duncan \(remove lock to reply\)

    Rudy Tovar Guest

    Your making it too difficult for him....

    You'd better explain the object...
     
    Rudy Tovar, Apr 16, 2004
    #2
  3. Jamie Duncan \(remove lock to reply\)

    Rudy Tovar Guest

    Got to check my spelling....

     
    Rudy Tovar, Apr 16, 2004
    #3
  4. Jamie Duncan \(remove lock to reply\)

    Jamie Duncan Guest

    And your gender reference


    Ms. Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 17, 2004
    #4
  5. Jamie Duncan \(remove lock to reply\)

    Jamie Duncan Guest

    then dimstyleObject is a collection of the dimstyles dimstyles, right? like:

    (setq dimstyleObject (vla-get-dimstyles *doc*))

    Thanks Jason. Now do I have to pretest for the existence of the new name?
    or can I setq like this?

    (setq flagwave (vla-put-name dimstyleObject "MyNewName"))

    and if flagwave is nil it worked? right?

    Am I actually getting this?


    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 17, 2004
    #5
  6. You can't rename a collection object, but you
    can rename an item from within the collection
    (if allowed and in this case, yes it is).

    You need to set dimstyleObject to be an item
    contianed in the dimstyle collection.

    You should test for the existence of the new
    name before you use vla-put-name, or you
    could wrap the whole thing in a vl-catch-all-apply
    and deal with the error (if it occurs).

    ; active document
    (setq *doc* (vla-get-activedocument (vlax-get-acad-object)))

    ; dimstyle collection <-- contains all dimstyles
    (setq dims (vla-get-dimstyles *doc*))

    ; dimstyle object from within the collection
    (setq item (vla-item dims "Standard"))

    ; apply new name, trapping error incase the
    ; new name already exists.
    (setq
    error
    (vl-catch-all-apply
    'vla-put-name
    (list item "MyNewName")) )

    ; if 'error' is an object returned by vl-catch-all-apply
    ; print the error message, otherwise renaming worked.
    (if (vl-catch-all-error-p error)
    (vl-catch-all-error-message error)
    (princ "renaming worked")
    )
     
    Jason Piercey, Apr 17, 2004
    #6
  7. Jamie Duncan \(remove lock to reply\)

    Jamie Duncan Guest

    Thanks for the help Jason!

    Now I have a startup routine that sets *docs* like you've done, I assume
    then that as a global it will be fine for the session. Correct?

    And to test - I assume tblsearch is fine? I've searched a bit through the
    vlisp to see if there is an equivalent but I couldn't find any.



    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 17, 2004
    #7
  8. Jamie Duncan \(remove lock to reply\)

    Jeff Mishler Guest

    Hi Jamie,
    This is about as close to "tblsearch" as you'll get with activex:

    (setq dims (vla-get-dimstyles *doc*))
    (if (not (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-item (list dims "mydim"))))
    (alert "Dim name found")
    (alert "Dim name not found")
    )

    HTH,
    Jeff
     
    Jeff Mishler, Apr 17, 2004
    #8
  9. Jamie Duncan \(remove lock to reply\)

    Paul Turvill Guest

    All other discussion notwithstanding, the brute force method:

    (command "_.rename" "_d" "OldName" "NewName")
    ___
     
    Paul Turvill, Apr 17, 2004
    #9
  10. The global will be valid for the life of the drawing
    it was initiated in, not necessarily the session.

    Tblsearch is one way to test for the existence,
    or you can do as Jeff has shown.

    (vla-item <collection> <item>) is the *same* as
    tblsearch in terms of activex. Just remember to
    trap for errors. If an error occurred, it failed.
     
    Jason Piercey, Apr 18, 2004
    #10
  11. Jamie Duncan \(remove lock to reply\)

    Joe Burke Guest

    Hi Jason,

    This Tony snip might help Jamie with the general idea.

    Joe

    ;;--------
    All ActiveX collection objects raise a 'Key Not found'
    exception when an attempt to reference a non-existing
    element is made. The proper way to test for membership
    in any collection object, is to call the collections
    Item() method in a protected block of code (passing the
    name of the item which you want to test for membership),
    and handling the exception that occurs if the element is
    not found.

    Here is an example:

    ;; Return T if the selection set whose
    ;; Name is passed as an argument exists
    ;; in the Active Document's selection
    ;; sets collection, or nil otherwise:

    (defun selection-set-exists? (Name)
    (not (vl-catch-all-error-p
    (vl-catch-all-apply
    'vla-Item
    (list
    (vla-get-SelectionSets
    (ThisDrawing)
    )
    Name
    )
    )
    )
    )
    )
    ;;--------
     
    Joe Burke, Apr 18, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.