Jump to content

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


lamensterms

Recommended Posts

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.

 

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

Link to comment
Share on other sites

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

(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:

(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)
)

Link to comment
Share on other sites

This way ?

 

(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

Link to comment
Share on other sites

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

 

(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)
)

Link to comment
Share on other sites

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.

Edited by lamensterms
Link to comment
Share on other sites

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:

 

(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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

Not knocking your reference, but be advised that DXF codes are added/removed from version to version, similarly, additional entities are added to later versions.

 

I would strongly advise using the latest AutoDesk DXF reference which includes documentation of all DXF codes for all available entities. Be aware that such a reference includes DXF codes for non-graphical entities such as Layers/Blocks/Styles etc, and for Dictionaries, such as MLineStyles, MLeaderStyles etc. in addition to references for advanced topics, such as working with the OCS, XData and XRecords.

Link to comment
Share on other sites

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