Jump to content

Help Modifying Converting Arc to Circle Lisp Code Please!


Recommended Posts

Posted

This routine (below) works but it only works on one arc at a time.

I'd like to move from ENTSEL to SSGET so I can convert

a bunch of arcs at once.

I think I could figure it out (given enough time) but since there are

so many here much more knowledgeable than I I'm sure you

guys can code this of the top of your head.

Doing in WHILE loops or counters are an extended trial and error effort

for me. Anyway, here's my code:

 

(DEFUN C:ATC (/ LAY EL ENM1 ARCLAY C RAD)

(SETVAR "CMDECHO" 0)

(COMMAND "UNDO" "M")

(Command "ucs" "w")

(PROMPT "\nArc to circle: ")

(setq olderr *error*

*error* ATCERR)

(SETQ LAY (GETVAR "CLAYER")

E1 (ENTSEL "SELECT ARC: "))

(IF E1 (PROGN

(SETQ ENM1 (CAR E1)

ARCLAY (CDR(ASSOC 8 (ENTGET ENM1)))

C (CDR (ASSOC 10 (ENTGET ENM1)))

RAD (CDR (ASSOC 40 (ENTGET ENM1))))

(ENTDEL ENM1)

(COMMAND "LAYER" "SET" ARCLAY "")

(COMMAND "CIRCLE" C RAD)

(COMMAND "LAYER" "SET" LAY "")))

(SETVAR "CMDECHO" 1)

(PRINC))

(defun AERR (s)

(if (/= s "Function cancelled")

(princ (strcat "\nCancel: " s)))

(setq A nil)

(setq *error* olderr)(PRINC))

 

I'm not claiming this to be the most efficient code but it works...

 

Thank you guys so much for all your help (and code!!)

Posted

I was actually pretty curious about creating a circle.

 

;;; Convert all selected Arcs to Circles (accounts for non WCS)
;;; Required Subroutines: AT:SS->List
;;; Alan J. Thompson, 09.10.09
(defun c:ATC (/ *error* #OldCmdecho #UCSFlag #SSList #ActiveDoc
             #ActiveSpace
            )

;;; error handler
 (defun *error* (#Message)
   (and #UCSFlag (vl-cmdf "_.ucs" "_previous"))
   (and #OldCmdecho (setvar "cmdecho" #OldCmdecho))
   (and #ActiveDoc (vla-EndUndoMark #ActiveDoc))
   (and
     #Message
     (or (member
           #Message
           '("console break" "Function cancelled" "quit / exit abort")
         ) ;_ member
         (princ (strcat "\nError: " #Message))
     ) ;_ or
   ) ;_ and
 ) ;_ defun

 (vl-load-com)

 (setq #OldCmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (or (zerop (getvar "worlducs"))
     (progn (setq #UCSFlag T)
            (vl-cmdf "_.ucs" "")
     ) ;_ progn
 ) ;_ or
 (cond
   ((setq #SSList (AT:SS->List (ssget ":L" '((0 . "ARC"))) T))
    (setq #ActiveDoc   (vla-get-activedocument (vlax-get-acad-object))
          #ActiveSpace
                       (if (or (eq acmodelspace
                                   (vla-get-activespace #ActiveDoc)
                               ) ;_ eq
                               (eq :vlax-true (vla-get-mspace #ActiveDoc))
                           ) ;_ or
                         (vla-get-modelspace #ActiveDoc)
                         (vla-get-paperspace #ActiveDoc)
                       ) ;_ if
    ) ;_ setq
    (vla-StartUndoMark #ActiveDoc)
    (foreach x #SSList
      (vl-catch-all-apply
        '(lambda ()
           (vla-addcircle
             #ActiveSpace
             (vla-get-center x)
             (vla-get-radius x)
           ) ;_ vla-addcircle
           (vla-put-layer
             (vlax-ename->vla-object (entlast))
             (vla-get-layer x)
           ) ;_ vla-put-layer
           (vla-delete x)
         ) ;_ lambda
      ) ;_ vl-catch-all-apply
    ) ;_ foreach
   )
 ) ;_ cond
 (*error* nil)
 (princ)
) ;_ defun

You will need this subroutine:

;;; Convert selection set to list of ename or vla objects
;;; #Selection - SSGET selection set
;;; #VLAList - T for vla objects, nil for ename
;;; Alan J. Thompson, 04.20.09
(defun AT:SS->List (#Selection #VlaList / #List)
 (and #Selection
      (setq #List (vl-remove-if
                    'listp
                    (mapcar 'cadr (ssnamex #Selection))
                  ) ;_ vl-remove-if
      ) ;_ setq
      #VlaList
      (setq #List (mapcar 'vlax-ename->vla-object #List))
 ) ;_ and
 #List
) ;_ defun

Posted

WOW! You are WAY out my league!!

Talk about something to aspire to!!

 

How is this done in plain autolisp?

(So I can see (and understand) HOW it's done?

I'm not at a skill level to understand VL....

 

I actually don't even know how to load this..

(I'm not afraid to admit my limited knowledge!!)

 

Do I just create a .lsp file with this code and load it like

any other lisp file??

 

Thanks so much!!!

Posted

Well...

I figured out loading it is no biggie..

 

Thanks!

 

 

I'd just like to see how to move from ENTSEL to SSGET with a loop.

Posted
WOW! You are WAY out my league!!

Talk about something to aspire to!!

 

How is this done in plain autolisp?

(So I can see (and understand) HOW it's done?

I'm not at a skill level to understand VL....

 

I actually don't even know how to load this..

(I'm not afraid to admit my limited knowledge!!)

 

Do I just create a .lsp file with this code and load it like

any other lisp file??

 

Thanks so much!!!

 

 

:) Glad you like it. VL seems really intimidating, but actually, so much easier to work with.

I actually went against what I would normally do and just gave you a bunch of code, completely disregarding what you had done. For that, I apologize.

To make it up, here's a slightly modified version of your code. It could still really use some cleanup work (procedures, etc.), but I wanted to get you to an ssget point (with a clean error handler).

 

(DEFUN C:ATC (/ *error* LAY E1 ENM1 ARCLAY C RAD #Count)
 ;;; error handler
 (defun *error* (#Message)
   (command "_.undo" "_end")
   (and
     #Message
     (or (member
           #Message
           '("console break" "Function cancelled" "quit / exit abort")
         ) ;_ member
         (princ (strcat "\nError: " #Message))
     ) ;_ or
   ) ;_ and
 ) ;_ defun
 
 (SETVAR "CMDECHO" 0)
 (COMMAND "UNDO" "_begin")
 (Command "ucs" "w")
 (PROMPT "\nArc to circle: ")
 (SETQ LAY (GETVAR "CLAYER")
       E1  (ssget ":L" '((0 . "ARC")))
 ) ;_ SETQ
 (IF E1
     (repeat (setq #Count (sslength E1))
       (setq #Count (1- #Count)
             ENM1 (ssname E1 #Count)
           ARCLAY (CDR (ASSOC 8 (ENTGET ENM1)))
           C      (CDR (ASSOC 10 (ENTGET ENM1)))
           RAD    (CDR (ASSOC 40 (ENTGET ENM1)))
     ) ;_ SETQ
     (ENTDEL ENM1)
     (COMMAND "LAYER" "SET" ARCLAY "")
     (COMMAND "CIRCLE" C RAD)
     (COMMAND "LAYER" "SET" LAY "")
       )
 ) ;_ IF
 (*error* nil)
 (SETVAR "CMDECHO" 1)
 (PRINC)
) ;_ DEFUN

Posted

No apology necessary!

I'm really impressed with the knowledge found here!

 

It works great!!

 

I can't thank you enough!!

Posted
No apology necessary!

I'm really impressed with the knowledge found here!

 

It works great!!

 

I can't thank you enough!!

 

Happy to help. :)

Don't ever hesitate to ask questions here. The only bad question is the one not asked.

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...