+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member lamensterms's Avatar
    Discipline
    Manufacture
    lamensterms's Discipline Details
    Occupation
    Steel Detailer
    Discipline
    Manufacture
    Details
    3D Modelling - Mechanical & Structural 2D Detailing - Shop Drawings
    Using
    AutoCAD 2010
    Join Date
    May 2011
    Location
    Berwick, VIC, Australia
    Posts
    169

    Default Extract center point and diameter of circle - then use these values in a routine...?

    Registered forum members do not see this ad.

    Hi Guys,

    I have a simple routine that will allow me to insert a block at a location, scale and rotation which are all determined by user inputs.

    The block is a hatched (solid) circle with crosshairs through it which we use to represent holes (steel detailing).

    Currently the routine asks the user for an insert point (which we pick at the center of an existing un-hatched circle), hole diameter and rotation angle.

    I would like to revise the routine so that it will only ask the user to select the existing circle and the routine will determine the insertion point and size by reading the values from the circle picked.

    Code:
    (defun C:HP (/ PT1 BOLTDIA)
       (setvar "cmdecho" 0)
       (setvar "osmode" 32)
       (SETQ PT1 (GETPOINT "\nPick Insertion Point. "))
       (SETQ BOLTDIA (ureal 1 "" "Enter Hole Diameter" 22))
       (COMMAND "INSERT" "HP" PT1 BOLTDIA "")
    (princ)
    )
    Is the current routine.

    Can someone please educate me as to which lisp functions to use (to extract center and diameter of circle) and how i can apply them to this routine?

    Any help is greatly appreciated.

    Thanks guys.

  2. #2
    Senior Member ketxu's Avatar
    Computer Details
    ketxu's Computer Details
    Operating System:
    Sorry, my English not well :(
    Computer:
    Sorry, my English not well :(
    Motherboard:
    Sorry, my English not well :(
    CPU:
    Sorry, my English not well :(
    RAM:
    Sorry, my English not well :(
    Graphics:
    Sorry, my English not well :(
    Primary Storage:
    Sorry, my English not well :(
    Secondary Storage:
    Sorry, my English not well :(
    Monitor:
    Sorry, my English not well :(
    Using
    AutoCAD 2007
    Join Date
    Sep 2010
    Location
    Sorry, my English not well :(
    Posts
    169

    Default

    You may be look into dxf 10 and 40 of a circle object.
    Code to get dxf sth like : (cdr (assoc DXF_code entity_record))
    Code:
    (setq circleObj (car(entsel "\nSelect circle :"));Get ename of circle object picked
    
    (setq  e_circleObj (entget circleObj)) ; Get record of Entity Circle
    (setq CenterPoint (cdr (assoc 10 e_circleObj))) ; Get Center Point by dxf 10
    (setq Radius (cdr (assoc 40 e_circleObj))) ; Get Radius by dxf 40
    Archive :
    (setq CenterPoint (cdr(assoc 10 (setq e_circleObj (entget(car(entsel "\nSelect Circle :"))))))
    Radius (cdr(assoc 40 e_circleObj)))
    Or maybe use VL:
    Code:
    (setq vla_circle (vlax-ename->vla-object (car (entsel "\nSelect Circle :"))) ;Get VLA Object Circle by (vlax-ename->vla-object ename)
             center (vlax-get  vla_circle 'center)
             Radius (vlax-get vla_circle 'Radius)
    )

  3. #3
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    This way ?

    Code:
    (defun c:test (/ ss j sset)
      ;; == Tharwat 01. 09. 2011 == ;;
      (if (and
            (progn
              (print "-->> Select Circle(s) please :")
              (setq ss (ssget '((0 . "CIRCLE"))))
            )
            (tblsearch "BLOCK" "HP")
          )
        (repeat (setq j (sslength ss))
          (setq sset (ssname ss (setq j (1- j))))
          (entmakex
            (list '(0 . "INSERT")
                  '(2 . "HP")
                  (cons 10 (trans (cdr (assoc 10 (entget sset))) 1 0))
                  '(41 . 1.0)
                  '(42 . 1.0)
                  '(43 . 1.0)
                  '(50 . 0.0)
            )
          )
        )
        (cond ((not ss) (alert "You did not select any Circle !! "))
              (t
               (alert
                 "Your block (HP) is not existed in the current drawing !! "
               )
              )
        )
      )
      (princ)
    )
    Tharwat
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  4. #4
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    6,000

    Default

    Of course, this is garbage if you have to specify the rotation. What determines that?

    Code:
    (defun c:Test (/ ss i data dxf40)
      (if (cond ((tblsearch "BLOCK" "HP"))
                ((findfile "HP.dwg") (command "_.-insert" "HP.dwg" nil) T)
          )
        (if (setq ss (ssget '((0 . "CIRCLE"))))
          (repeat (setq i (sslength ss))
            (entmakex (list '(0 . "INSERT")
                            '(2 . "HP")
                            (assoc 10 (setq data (entget (ssname ss (setq i (1- i))))))
                            (cons 41 (setq dxf40 (cdr (assoc 40 data))))
                            (cons 42 dxf40)
                            (cons 43 dxf40)
                      )
            )
          )
        )
        (alert "Block \"HP\" cannot be found!")
      )
      (princ)
    )
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  5. #5
    Senior Member lamensterms's Avatar
    Discipline
    Manufacture
    lamensterms's Discipline Details
    Occupation
    Steel Detailer
    Discipline
    Manufacture
    Details
    3D Modelling - Mechanical & Structural 2D Detailing - Shop Drawings
    Using
    AutoCAD 2010
    Join Date
    May 2011
    Location
    Berwick, VIC, Australia
    Posts
    169

    Default

    thanks a lot for all your help guys, i will test out those routines and let you know how i go.

    alanjt - the rotation angle of the hole symbol would need to be in the same direction (square to) the direction of the member. It would probably be a good idea for me to set the default rotation of the symbol to zero, then the user can rotate manually after the block has been inserted.

    Thanks again guys.

    -----------EDIT----------

    After quickly testing those routines, i have found that they both insert the symbol block by picking circle(s) - which is great.

    Tharwat - i found that your routine didnt scale the inserted block to suit the size of the circle picked - the block (HP) just came in at the original scale.

    alanjt - i found that your routine manages to scale the inserted block by only half the required size (im guessing the routine measured the radius rather than the diameter of the circle picked). I resolved this easily by scaling up the block in the source DWG by x2.

    Thanks again for your help guys, im thrilled with the way this routine runs now - it will save us lots of time in the office (and also improve our drawing presentation).

    Cheers.
    Last edited by lamensterms; 2nd Sep 2011 at 12:50 am.

  6. #6
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    6,000

    Default

    Quote Originally Posted by lamensterms View Post
    thanks a lot for all your help guys, i will test out those routines and let you know how i go.

    alanjt - the rotation angle of the hole symbol would need to be in the same direction (square to) the direction of the member. It would probably be a good idea for me to set the default rotation of the symbol to zero, then the user can rotate manually after the block has been inserted.

    Thanks again guys.

    -----------EDIT----------

    After quickly testing those routines, i have found that they both insert the symbol block by picking circle(s) - which is great.

    Tharwat - i found that your routine didnt scale the inserted block to suit the size of the circle picked - the block (HP) just came in at the original scale.

    alanjt - i found that your routine manages to scale the inserted block by only half the required size (im guessing the routine measured the radius rather than the diameter of the circle picked). I resolved this easily by scaling up the block in the source DWG by x2.

    Thanks again for your help guys, im thrilled with the way this routine runs now - it will save us lots of time in the office (and also improve our drawing presentation).

    Cheers.
    I'm such a tard. You are correct, I wasn't thinking about diameter. Try this:

    Code:
    (defun c:Test (/ ss i data dia)
      (if (cond ((tblsearch "BLOCK" "HP"))
                ((findfile "HP.dwg") (command "_.-insert" "HP.dwg" nil) T)
          )
        (if (setq ss (ssget '((0 . "CIRCLE"))))
          (repeat (setq i (sslength ss))
            (entmakex (list '(0 . "INSERT")
                            '(2 . "HP")
                            (assoc 10 (setq data (entget (ssname ss (setq i (1- i))))))
                            (cons 41 (setq dia (* (cdr (assoc 40 data)) 2.)))
                            (cons 42 dia)
                            (cons 43 dia)
                      )
            )
          )
        )
        (alert "Block \"HP\" cannot be found!")
      )
      (princ)
    )
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  7. #7
    Senior Member lamensterms's Avatar
    Discipline
    Manufacture
    lamensterms's Discipline Details
    Occupation
    Steel Detailer
    Discipline
    Manufacture
    Details
    3D Modelling - Mechanical & Structural 2D Detailing - Shop Drawings
    Using
    AutoCAD 2010
    Join Date
    May 2011
    Location
    Berwick, VIC, Australia
    Posts
    169

    Default

    haha, thanks a lot for fixing that up alanjt. The routine works brilliantly.

    I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.

    Thanks again mate.

  8. #8
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2011
    Join Date
    Apr 2008
    Posts
    6,000

    Default

    Quote Originally Posted by lamensterms View Post
    haha, thanks a lot for fixing that up alanjt. The routine works brilliantly.

    I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.

    Thanks again mate.
    Not a problem.

    I have a new link bookmarked at work, but I won't be back in until Monday, but I had this one saved in a txt file: http://images.autodesk.com/adsk/files/acad_dxf1.pdf
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  9. #9
    Senior Member lamensterms's Avatar
    Discipline
    Manufacture
    lamensterms's Discipline Details
    Occupation
    Steel Detailer
    Discipline
    Manufacture
    Details
    3D Modelling - Mechanical & Structural 2D Detailing - Shop Drawings
    Using
    AutoCAD 2010
    Join Date
    May 2011
    Location
    Berwick, VIC, Australia
    Posts
    169

    Default

    Fantastic - thanks again alanjt. That will come in very handy once i start learning how to use them.

    Cheers.

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,718

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by lamensterms View Post
    I was just wondering if you could please point me in the direction of any resources for what each DXF code represents. Ive taken a quick look here, but it only list a range (40-48 ) for floating point values.
    I find an online reference is sometimes easier to navigate, here is a list of references that may also help you.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Replies: 7
    Last Post: 29th Dec 2010, 06:12 pm
  2. circle center line(Like Plus symbol and after circle 4 sides 5mm extra length)
    By johnpieter in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 19th Dec 2010, 02:23 pm
  3. Diameter circle with a centermark?
    By SFG13 in forum AutoCAD Beginners' Area
    Replies: 8
    Last Post: 26th Apr 2010, 09:45 pm
  4. Replies: 5
    Last Post: 3rd Dec 2009, 12:40 pm
  5. vl circle diameter
    By fuccaro in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 30th Jul 2009, 02:37 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