+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 19 of 19
  1. #11
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,400

    Default

    Registered forum members do not see this ad.

    Try this, yes there is a very small error but can you tell ? Not sure how far I can push the 0.00000001
    Code:
    ; circle to donut by Homer simson who loves donuts
    ; actually Alan H March 2018
    
    (defun c-donut (/ obj cenpt rad width off oldaunits oldsnap)
    
      (setq obj (vlax-ename->vla-object (car (entsel "\nPick circle"))))
    
      (setq	cenpt (vlax-safearray->list
    		(vlax-variant-value (vla-get-center obj))
    	      )
      )
      (setq rad (vla-get-radius obj))
    
      (if (not aH:getval2)    (load "getvals3")
      )
    
      (ah:getval2
        "Enter width" 5	4     "5"
        "Enter offset +ve -ve "	5	4     "0"
       )
    
      (setq width (atof val1))
      (setq off (atof val2))
      (setq rad (+ rad off))
    
      (setq oldaunits (getvar "aunits"))
      (setvar 'aunits 3)
      (setq oldsnap (getvar 'osmode))
      (setvar 'osmode 0)
    
      (entmakex (list (cons 0 "ARC")
    		  (cons 10 cenpt)
    		  (cons 40 rad)
    		  (cons 50 0.0)
    		  (cons 51 (- (* pi 2.0) 0.0000001))
    	    )
      )
    
      (command "pedit" (entlast) "Y" "w" width "")
    
      (setvar 'aunits oldaunits)
      (setvar 'osmode oldsnap)
      (princ)
    )
    
    (c-donut)
    Last edited by BIGAL; 21st Mar 2018 at 11:42 am.
    A man who never made mistakes never made anything

  2. #12
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    10,295

    Default

    Quote Originally Posted by BIGAL View Post
    Try this, yes there is a very small error but can you tell ? Not sure how far I can push the 0.00000001
    There's seems to be a problem. I load and run the routine, it asks me to pick a circle, I click on a circle and then it quits and says the operation has been cancelled.
    Attached Images
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

  3. #13
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,400

    Default

    Do apologise left out the dcl asking for width and offset.
    Attached Images
    Attached Files
    A man who never made mistakes never made anything

  4. #14
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    10,295

    Default

    Thanks but it's still not working for me. I'm not sure why a dcl is needed? After the circle is converted, it should just be a simple call for Pedit to set width. Incorporating a dcl to open a dialog seems overly complicated. Maybe I'll take a look at it this weekend and see if I can tweak it to do what I want.
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

  5. #15
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    10,295

    Default

    Actually, it was pretty simple to add the function. I just added a single line of code at the end of dtkell's routine, before the (princ).

    (command "_.pedit" (entlast) "w" pause "")

    Now it does what I want.
    Last edited by Cad64; 22nd Mar 2018 at 06:30 pm.
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

  6. #16
    Quantum Mechanic
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,400

    Default

    Hi Cad64 if you dont want the dcl just change the lines as in next code snippet. I took into account the next request can we have the pline at a different offset than the circle see diagram previous post, the dcl asks two questions width and offset, the offset can be predefined so it is a click on ok as the offset of zero means it is central over the existing circle. This also allows the circle to be an edge of the new pline. width = 5 offset= 2.5

    It is just me I have moved more to not looking down and entering line after line, by using the library dcl, you can use it in any program maybe you thought it was hard coded, it creates the dcl in the Autocad defined temporary directory. (setq fname (vl-filename-mktemp "" "" ".dcl")) In terms of response time I have not had any lag in popping up on the screen.

    Code:
    (if (not aH:getval2)    (load "getvals3")   )
    (ah:getval2  "Enter width" 5 4     "5"     "Enter offset +ve -ve " 5 4     "0"    )
    (setq width (atof val1))
    (setq off (atof val2))
     
    remove these 
    (if (not aH:getval2)    (load "getvals3")   )
    (ah:getval2  "Enter width" 5 4     "5"     "Enter offset +ve -ve " 5 4     "0"    )
    change these
    (setq width (getreal "Enter width "))
    (setq off (getreal "Enter offset"))
    Sample code getvals3.lsp for 1,2 or 3 inputs
    Code:
    (if (not aH:getval2)    (load "getvals3")   ) ; returns val1 as string
    (ah:getval1 "Line 1" 5 4 "default")
    (ah:getval2  "Enter width" 5 4     "5"     "Enter o ffset +ve -ve " 5 4     "0"    ) ; returns val1 val2 as strings
    (ah:getval3 "Line 1" 5 4 "default1" "Line2" 8 7 "default2" "Line 3" 6 4 "123") ; val1 val2 val3 as strings
    Attached Images
    Last edited by BIGAL; 24th Mar 2018 at 12:40 am.
    A man who never made mistakes never made anything

  7. #17
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2018
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    12,040

    Default

    Quote Originally Posted by dtkell View Post
    I have used this with success for a long time.

    Code:
    ;;  CirclePolylineSwap.lsp [command names: C2P & P2C]
    ;;  Two commands, to convert in both directions between a Circle and a circular
    ;;  (two-equal-arc-segment closed) Polyline, such as the Donut command makes.
    ;;  Both commands:
    ;;  1. ask User to select again if they miss, pick an incorrect object type, or pick an
    ;;      object on a locked Layer;
    ;;  2. remove selected/converted object, but can easily be edited to retain it;
    ;;  3. account for different Coordinate Systems;
    ;;  4. retain non-default/non-Bylayer color, linetype, linetype scale, lineweight,
    ;;      and/or thickness.
    ;;  See additional notes above each command's definition.
    ;;  Kent Cooper, May 2011
    
    ;;  C2P
    ;;  To convert a selected Circle to a two-equal-arc-segment closed zero-
    ;;  width Polyline circle [Donut w/ equal inside & outside diameters],
    ;;  which can then be modified as desired [given width, etc.], since Pedit
    ;;  will not accept selection of a Circle.
    ;
    (defun C:C2P (/ *error* cmde csel cir cdata cctr crad cextdir pdata)
      (vl-load-com)
      (defun *error* (errmsg)
        (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
          (princ (strcat "\nError: " errmsg))
        ); end if
        (command "_.undo" "_end")
        (setvar 'cmdecho cmde)
      ); end defun - *error*
      (setq cmde (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (command "_.undo" "_begin")
      (prompt "\nTo convert a Circle to its Polyline equivalent,")
      (while
        (not
          (and
            (setq csel (ssget ":S" '((0 . "CIRCLE"))))
            (= (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (entget (ssname csel 0))))))) 0)
              ; 0 for Unlocked, 4 for Locked
          ); end and
        ); end not
        (prompt "\nNothing selected, or not a Circle, or on a Locked Layer.")
      ); end while
      (setq
        cir (ssname csel 0); Circle entity name
        cdata (entget cir); entity data
        cctr (cdr (assoc 10 cdata)); center point, OCS for Circle & LWPolyline w/ WCS 0,0,0 as origin
        crad (cdr (assoc 40 cdata)); radius
        cextdir (assoc 210 cdata); extrusion direction
      ); end setq
      (setq 
        pdata (vl-remove-if-not '(lambda (x) (member (car x) '(67 410 8 62 6 48 370 39))) cdata)
          ; start Polyline entity data list -- remove Circle-specific entries from
          ; Circle's entity data, and extrusion direction; 62 Color, 6 Linetype, 48
          ; LTScale, 370 LWeight, 39 Thickness present only if not default/bylayer
        pdata
          (append ; add Polyline-specific entries
            '((0 . "LWPOLYLINE") (100 . "AcDbEntity"))
            pdata ; remaining non-entity-type-specific entries
            '((100 . "AcDbPolyline") (90 . 2) (70 . 129) (43 . 0.0))
              ; 90 = # of vertices, 70 1 bit = closed 128 bit = ltype gen. on, 43 = global width
            (list
              (cons 38 (caddr cctr)); elevation in OCS above WCS origin [Z of Circle center]
              (cons 10 (list (- (car cctr) crad) (cadr cctr))); vertex 1
              '(40 . 0.0) '(41 . 0.0) '(42 . 1); 0 width, semi-circle bulge factors
              (cons 10 (list (+ (car cctr) crad) (cadr cctr))); vertex 2
              '(40 . 0.0) '(41 . 0.0) '(42 . 1)
              cextdir ; extr. dir. at end [if in middle, reverts to (210 0.0 0.0 1.0) in (entmake)]
            ); end list
          ); end append & pdata
      ); end setq
      (entmake pdata)
      (entdel cir); [remove or comment out this line to retain selected Circle]
      (command "_.undo" "_end")
      (setvar 'cmdecho cmde)
      (princ)
    ); end defun
    
    ;;  P2C
    ;;  To convert a selected closed two-equal-arc-segment global-width circular
    ;;  Polyline [Donut] to a true Circle.  If selected Polyline has non-zero global
    ;;  width, offers User option to draw Circle along center-line or along inside or
    ;;  outside edge of width, and retains choice as default for next use.
    ;;  Works on both old-style "heavy" and newer "lightweight" Polylines.
    ;;  [Will not work on one with more than two segments, or with two unequal-
    ;;  included-angle segments, even if truly circular.]
    ;
    (defun C:P2C (/ *error* cmde psel pl pdata pwidadj cposdef cpostemp pv1 pv2 cdata)
      (vl-load-com)
      (defun *error* (errmsg)
        (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
          (princ (strcat "\nError: " errmsg))
        ); end if
        (command "_.undo" "_end")
        (setvar 'cmdecho cmde)
      ); end defun - *error*
      (setq cmde (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (command "_.undo" "_begin")
      (prompt "\nTo convert a Polyline circle to a true Circle,")
      (while
        (not
          (and
            (setq psel (ssget ":S" '((0 . "*POLYLINE"))))
            (if psel (setq pl (ssname psel 0) pdata (entget pl)))
            (= (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 pdata))))) 0)
              ; 0 for Unlocked, 4 for Locked
            (if (= (cdr (assoc 0 pdata)) "POLYLINE"); "heavy" Polyline
              (progn; then
                (command "_.convertpoly" "_light" pl ""); retains same entity name
                (setq pdata (entget pl)); replace "heavy" Polyline entity data
              ); end progn
              T; else - to not return nil for LWPolyline
            ); end if
            (member '(90 . 2) pdata); two vertices
            (member '(42 . 1.0) (cdr (member '(42 . 1.0) pdata))); two half-circle bulge factors
              ; needs to be really precise -- will be for one made with Donut,
              ; but may not be for one made with, for example, Pline [pt] Arc
              ; Direction [direction] [halfway around] Close, even with Snap on
          ); end and
        ); end not
        (prompt "\nNothing selected, or not a circular Polyline [Donut], or on a Locked Layer.")
      ); end while
      (if (and (assoc 43 pdata) (/= (cdr (assoc 43 pdata)) 0)); global non-zero width
        (progn; then
          (initget "Center Inside Outside")
          (setq
            pwidadj (/ (cdr (assoc 43 pdata)) 2)
            cposdef (cond (_P2Ccpos_) (T "Center")); Center default on first use
            cpostemp
              (getkword
                (strcat
                  "\nCircle position on Donut [Center/Inside/Outside] <"
                  (substr cposdef 1 1)
                  ">: "
                ); end strcat
              ); end getkword & cpostemp
            _P2Ccpos_ (cond (cpostemp) (cposdef))
          ); end setq
        ); end progn
        (setq pwidadj 0); else
      ); end if
      (setq
        pv1 (cdr (assoc 10 pdata)); = Polyline Vertex 1 [XY]
        pv2 (cdr (assoc 10 (cdr (member (assoc 10 pdata) pdata)))); = Polyline Vertex 2 [XY]
          ; can't use parameter XYZ WCS locations, because cdata needs XY OCS locations
        cdata (vl-remove-if-not '(lambda (x) (member (car x) '(67 410 8 62 6 48 370 39))) pdata)
          ; build circle entity data list -- remove Polyline-specific entries from
          ; Polyline's entity data, and extrusion direction; 62 Color, 6 Linetype, 48
          ; LTScale, 370 LWeight, 39 Thickness present only if not default/bylayer
        cdata
          (append ; add circle-specific entries
            '((0 . "CIRCLE") (100 . "AcDbEntity"))
            cdata ; remaining non-entity-type-specific entries
            (list
              '(100 . "AcDbCircle")
              (list
                10 ; center
                (/ (+ (car pv1) (car pv2)) 2); X = halfway between X's of vertices
                (/ (+ (cadr pv1) (cadr pv2)) 2); Y = halfway between Y's of vertices
                (cdr (assoc 38 pdata))); Z of Circle = elevation of Pline
              (cons
                40 ; radius
                (+
                  (/
                    (distance; diameter -- needs 3D points for 3D distance
                      (vlax-curve-getStartPoint pl)
                      (vlax-curve-getPointAtParam pl 1)
                    ); end distance
                    2
                  ); end /
                  (cond
                    ((= _P2Ccpos_ "Inside") (- pwidadj))
                    ((= _P2Ccpos_ "Outside") pwidadj)
                    (T 0); Pline with width & Center option, or no width/no position prompt
                  ); end cond
                ); end +
              ); end cons
              (assoc 210 pdata); extr. dir. at end [if in middle, reverts to (210 0.0 0.0 1.0) in (entmake)]
            ); end list
          ); end append & cdata
      ); end setq
      (entmake cdata)
      (entdel pl)
        ; [remove or comment out above line to retain selected
        ; Polyline -- will be left lightweight if originally heavy]
      (command "_.undo" "_end")
      (setvar 'cmdecho cmde)
      (princ)
    ); end defun
    (prompt "\nType C2P to convert a Circle to its Polyline equivalent.")
    (prompt "\nType P2C to convert a circular Polyline to its Circle equivalent.")
    That's the LISP I have, it came from CADALYST.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  8. #18
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2018
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    12,040

    Default

    Quote Originally Posted by Cad64 View Post
    Actually, it was pretty simple to add the function. I just added a single line of code at the end of dtkell's routine, before the (princ).

    (command "_.pedit" (entlast) "w" pause "")

    Now it does what I want.
    I'll have to check that out, thanks!
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  9. #19
    Super Moderator Cad64's Avatar
    Computer Details
    Cad64's Computer Details
    Operating System:
    Windows 7 Profesional x64
    Computer:
    XI Computers
    Motherboard:
    Asus P8Z77-V Pro
    CPU:
    Intel Core I7 3770K 4.1 Ghz Quad Core 3rd Gen
    RAM:
    24GB DDR3 @ 1333MHz
    Graphics:
    Nvidia GeForce GTX 570 1280MB GDDR5
    Primary Storage:
    SATAII 500GB 7200 RPM
    Secondary Storage:
    Western Digital My Book Studio Edition II - 2TB capacity
    Monitor:
    HPf2105 21" LCD Widescreen & Cintiq 21ux
    Discipline
    Multi-disciplinary
    Cad64's Discipline Details
    Occupation
    Freelance Digital Artist
    Discipline
    Multi-disciplinary
    Details
    3D model building, texturing and rendering. Photoshop Color Graphics.
    Using
    AutoCAD 2014
    Join Date
    Feb 2006
    Location
    Southern California
    Posts
    10,295

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by SLW210 View Post
    I'll have to check that out, thanks!
    Just to be clear, there are two functions inside this routine. One is the C2P function which converts the circle to polyline. The other is the P2C function which does something else. I'm only concerned with the C2P function, so I added the line of code at the end of that section. See below.
    Attached Images
    CGSociety Portfolio: http://rdeweese.cgsociety.org/
    Facebook:
    https://www.facebook.com/rdeweese67/


    "Work Smart, Not Hard"

Similar Threads

  1. Draw Polyline with global width?
    By comcu in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 2nd Jul 2008, 10:32 am
  2. Create a circle with a width
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 30th Nov 2007, 11:10 pm
  3. Replies: 0
    Last Post: 24th Jan 2007, 11:10 pm
  4. Polylines with Global Width to Boundaries
    By daiharv in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 20th Dec 2006, 10:00 am
  5. global width lines
    By drahcir in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 19th Oct 2006, 12:48 pm

Bookmarks

Posting Permissions

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