lamensterms Posted September 1, 2011 Share Posted September 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
ketxu Posted September 1, 2011 Share Posted September 1, 2011 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) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 1, 2011 Share Posted September 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 1, 2011 Share Posted September 1, 2011 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) ) Quote Link to comment Share on other sites More sharing options...
lamensterms Posted September 1, 2011 Author Share Posted September 1, 2011 (edited) 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 September 1, 2011 by lamensterms Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 2, 2011 Share Posted September 2, 2011 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) ) Quote Link to comment Share on other sites More sharing options...
lamensterms Posted September 2, 2011 Author Share Posted September 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 2, 2011 Share Posted September 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
lamensterms Posted September 2, 2011 Author Share Posted September 2, 2011 Fantastic - thanks again alanjt. That will come in very handy once i start learning how to use them. Cheers. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 2, 2011 Share Posted September 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
pman860507 Posted September 2, 2011 Share Posted September 2, 2011 (edited) i normally use. Check out below. So i removed it. Edited September 2, 2011 by pman860507 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 2, 2011 Share Posted September 2, 2011 i normally use. http://www.jefferypsanders.com/autolispexp_enti.html# 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. Quote Link to comment Share on other sites More sharing options...
pman860507 Posted September 2, 2011 Share Posted September 2, 2011 Thats good to know. i removed my reference. I will check out the Autodesk Reference. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 2, 2011 Share Posted September 2, 2011 Here is the online version that I personally use: http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WSfacf1429558a55de185c428100849a0ab7-5f35.htm Navigate using the tabs along the left-hand side. Quote Link to comment Share on other sites More sharing options...
lamensterms Posted September 5, 2011 Author Share Posted September 5, 2011 That's great, thanks a lot guys. haha, i look forward to being able to put some of those to use. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.