See the top rated post in this thread. Click here

Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Points to Circles

  1. #11
    Member
    Join Date
    2017-04
    Posts
    2
    Login to Give a bone
    0

    Default Re: Points to Circles

    Is there a way to gets this lisp to only changes points on layer "DOT" to circles and keep the new circles on the same layer?

  2. #12
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Points to Circles

    Filter
    (8 . ¨DOT)
    Do the trick

    Code:
    (defun c:pt2cir ()
    (setq sset (ssget "_X" '((0 . "POINT")(8 . "DOT" ))) i 0)
    (if sset
      (repeat (sslength sset)    
        (setq ent (ssname sset i))
        (entmake
          (list
            (cons 0 "CIRCLE")
            (cons 8 "DOT")
            (cons 10 (cdr (assoc 10 (entget ent))))
            (cons 40 10.0) ;circle size, change the 10.0 to whatever you want
          )
        )
        (entdel ent)
        (setq i (1+ i))
      )
    )
    (princ)
    )
    (prompt "\n TYPE PT2CIR at the command line")

  3. #13
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Points to Circles

    Quote Originally Posted by devitg.89838 View Post
    Code:
    (defun c:pt2cir ()
    (setq sset (ssget "_X" '((0 . "POINT")(8 . "DOT" ))) i 0)
    (if sset
      (repeat (sslength sset)    
        (setq ent (ssname sset i))
        (entmake
          (list
            (cons 0 "CIRCLE")
            (cons 8 "DOT")
            (cons 10 (cdr (assoc 10 (entget ent))))
            (cons 40 10.0) ;circle size, change the 10.0 to whatever you want
          )
        )
        (entdel ent)
        (setq i (1+ i))
      )
    )
    (princ)
    )
    (prompt "\n TYPE PT2CIR at the command line")
    Hi devitg,

    A few comments if you would like to improve your codes.
    - Always localize your variables to avoid any mix up with other programs on your system and to avoid hair pull.
    The following line of codes:
    Code:
       (cons 10 (cdr (assoc 10 (entget ent))))
    is equal to:
    Code:
      (assoc 10 (entget ent))
    And you can remove the variable sset which is in front of the 'IF' function and just move the 'IF' function to be for eg: (if (setq sset (... etc

    Hope this helps.

  4. #14
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Points to Circles

    Eg:
    Code:
    (defun c:pt2cir ( / sset i ent)
    (if (setq sset (ssget "_X" '((0 . "POINT") (8 . "DOT"))))
      (repeat (setq i (sslength sset)    )
        (setq ent (ssname sset (setq i (1- i))))
        (if (entmake (list '(0 . "CIRCLE") '(8 . "DOT") (assoc 10 (entget ent)) (cons 40 10.0)))
          (entdel ent)
          )
        )
      )
    (princ)
    )
    (prompt "\n TYPE PT2CIR at the command line")

  5. #15
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    1

    Default Re: Points to Circles

    I thought maybe I would throw in an activeX example.

    I would also like to mention to you all that coding has other priorities than the fewest number of characters or speed.

    I would suggest you also consider stability. LISP has always been an unstable language that crashes easily.

    I have found placing errortraps around expressions that may cause a problem (like a locked layer for example) helps.

    Function syntax that looks like a try catch works better (IMO)

    I also try to not nest statements (although that is what lisp is good at), so I can test each expression to make sure it was
    successful before using the value in the next expression.

    I also absolutely do not like short non-descriptive variable names... X is not a variable name unless used in a lambda expression.

    I know the reddick naming convention has fallen out of favor, but to me coding without clear variable names is just sloppy code.

    If you cannot figure out what an expression is doing right away, you need more comments and clear variable/function naming.

    I wrote a project for a customer that had over 10000 lines of code and it was like 2 meg, so size is never a problem with LISP.

    OK I will get down off my soap box...



    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line Function to convert points to circles (including in block definitions)
    ;___________________________________________________________________________________________________________|
    
    (defun C:PointToCircle (/ objActiveDocument objBlock objPoint strBlockName strSearchBlocks)
     (initget 0 "Y N")
     (setq objActiveDocument (vla-get-activedocument (vlax-get-acad-object)))
     (if (or (setq strSearchBlocks (getkword "\nChange Points in Blocks Too? <Y> "))
             (not strSeachBlocks)
         )
      (vlax-for objBlock (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (setq strBlockName (vla-get-name objBlock))
       (if (or (= strSearchBlocks "Y")
               (= (substr strBlockName 1 1) "*")
           )
        (vlax-for objItem objBlock
         (if (= (vla-get-objectname objItem) "AcDbPoint")
          (and
           (setq lstInsertion (vlax-get objItem "coordinates"))
           (errortrap '(setq objCircle (vlax-invoke objBlock "addcircle" lstInsertion 1.0)))
           (errortrap '(vla-put-layer objCircle (vla-get-layer objItem)))
           (errortrap '(vla-delete objItem))
          )
         )
        ) 
       )
      )
     )
     (errortrap '(vla-regen objActiveDocument 1))
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to trap expression errors
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (XYZ)(set XYZ (eval symFunction)))
                          (list 'result))))
      nil
      (or result 
          'T
      )
     )
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2017-10-10 at 01:02 AM.
    AutomateCAD

  6. #16
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Points to Circles

    Hi Peter, tharwat, thanks for your tips.
    First all , it was my fault not to mention that the lisp it is not mine.

    Even I do not know where I got it .

    Maybe it was here.


    http://www.cadtutor.net/forum/showthread.php?
    13470-Converting-an-object-into-an-other


    Peter I used your errortrap defun , and I saw that it had a la DEBUG mode

    Code:
    ;; BY  Peter Jamtgaard-01
    (DEFUN ERRORTRAP  (SYMFUNCTION / OBJERROR RESULT)
      (IF (VL-CATCH-ALL-ERROR-P
            (SETQ OBJERROR (VL-CATCH-ALL-APPLY
                             '(LAMBDA (X) (SET X (EVAL SYMFUNCTION)))
                             (LIST 'RESULT))))
        (PROGN
          (IF DEBUG
            (PRINC
              (STRCAT "\n"
                      (VL-PRINC-TO-STRING (VL-CATCH-ALL-ERROR-MESSAGE OBJERROR))
                      "\nWhile evaluating the expression: "
                      (VL-PRINC-TO-STRING SYMFUNCTION)
                      "\n"
                      )
              )
            )
          NIL
          )
        (IF RESULT
          RESULT
          'T)
        )
      )
    ;;;(while (not (errortrap (quote (setq region (car (vlax-invoke model "addregion" (list poly-reg )))))))
    ;;; (princ "\nzError: Invalid polyline ")
    ;;; ; Call your function for selecting the polyline here
    ;;;)
    There is any change to it.?

    And as another way to error trap I use a RECURSIVE defun

    I have to dig in my lsp to find a sample .

    Thanks again.

  7. #17
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    1

    Default Re: Points to Circles

    there is no real change to the errortrap function, I just removed the debug mode because I don't use it and it makes the code more complicated.

    The vlax-catch-all-apply expression requires you to pass it a list and accidentally I found out that you can pass it the result as a list.

    This was fortuitous because I write code that checks for success by the expression either returning a nil or T/Vaue. nil for failure.

    If you wrap all of your expressions with an "and" expression the function will continue until it fails and drop out very similar to a try catch in .NET.

    In lisp would look like this.

    Code:
    (if (and expression1
             expression2
             ....
       )
     return value
     catch expressions
    )
    AutomateCAD

  8. #18
    Woo! Hoo! my 1st post
    Join Date
    2017-10
    Posts
    1
    Login to Give a bone
    0

    Default Re: Points to Circles

    Thank you for sharing this lisp! I was wondering if there is anyway to change it so that when I convert the points they can stay with the layers assigned to them. I mark utilities and there are several different ones, when I insert the command it changes all points to the current layer being used. i have tried to turn off some of the points before inserting it but it still does it. Thank you again and I hope there is an easier way than manually changing them all.

  9. #19
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Points to Circles

    Hi Timothy,

    The example C:PointToCircle I posted 4 replys above maintains the layer between the point and the new circle.

    There is a downloadable file in that response I added for you too.

    Peter
    AutomateCAD

Page 2 of 2 FirstFirst 12

Similar Threads

  1. circles within circles...
    By IamMichaelPacker747327 in forum AutoCAD General
    Replies: 9
    Last Post: 2012-04-30, 08:03 PM
  2. Circles Masking
    By ekolto in forum AutoCAD General
    Replies: 3
    Last Post: 2011-10-25, 07:33 PM
  3. Circles & Boxes.....
    By ronie_ernanto in forum AutoCAD Gallery
    Replies: 13
    Last Post: 2009-05-05, 09:03 AM
  4. Replies: 0
    Last Post: 2007-04-27, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •