magan Posted November 16, 2014 Posted November 16, 2014 Hello everyone. I am currently using AutoCAD2014. I am trying to code the program using AutoLISP. I am having 3D solid with some holes. I want to get the center of the circular hole and (length-width) of rectangular hole. and the output data has to be printed in the command prompt of autoCAD as output. This is all to be done with just single click on object. I am here providing the image of my object as well. Please, someone help me. Quote
BIGAL Posted November 17, 2014 Posted November 17, 2014 Maybe copy object to somewhere explode twice you can find circles but rectang becomes lines a bit of smart coding would reveal LxW use bounding box of 3d solid for limits and copy a known amount so you can work out object cen pts etc. use (ssget (assoc 0 "Circle,Lines")) Lee-mac posted a possible solution for this http://www.cadtutor.net/forum/showthread.php?35506-How-to-get-Region-coordinates/page2 Quote
magan Posted November 17, 2014 Author Posted November 17, 2014 Thank you for the help, But,I don't know what is the reason it's not working. Let me make this problem easy.I will initially work in the 2D of this component. If this 2D component is blocked as one. And then if I want centres of circles and (length-width) of rectangle, what can be done? Please help me. Quote
hanhphuc Posted November 19, 2014 Posted November 19, 2014 maybe you can try convert to block as Marko suggested Command: flatshot Quote
magan Posted November 20, 2014 Author Posted November 20, 2014 sir, can you give me much program hint regarding this. Because, I am new in this coding, which is making difficulty in proceeding further. please help me sir.. Quote
hanhphuc Posted November 20, 2014 Posted November 20, 2014 (edited) This example is just start point which to get circle coordinates from solid. method as proposed by Mr.Alan (BIGAL) at post#2 update v1.1 additional export csv as requested by amili @post#15 7/02/15 (vl-load-com) (defun c:test (/ i e p1 p2 ss lst q var[color="red"] f fn dat dat1[/color]) ;hanhphuc 2014 (set 'var (getvar 'cmdecho )) (setvar 'cmdecho 0) (if (and (setq e (entsel "\nPlease select solid.. ")) (setq e (car e)) (= (cdr (assoc 0 (entget e))) "3DSOLID")) (progn (vla-GetBoundingBox (setq obj (vlax-ename->vla-object e)) 'p1 'p2) (mapcar ''((a b) (set a (vlax-safearray->list b))) '(p1 p2) (list p1 p2)) (command "_explode" e) (setq i 0 ss (ssget "C" p1 p2) lst (mapcar '(lambda(x) (setq q nil) (if (= (cdr (assoc 0 (entget x))) "REGION") (setq q (cons (LM:reg x) q)) (setq q (cons (vlax-ename->vla-object x) q)) ) (if (listp q) (LM:flatten q) q ) ) (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ) ;_ end of mapcar ) ;_ end of setq (foreach o (vl-remove-if-not ''((x) (= (vla-get-ObjectName x) "AcDbCircle")) (LM:flatten lst)) (setq dat(cons (princ (strcat [color="red"]"\nCIRCLE_"[/color] (itoa (setq i (1+ i))) [color="red"]" "[/color] (vl-princ-to-string (mapcar ''((x)(vlax-get o x)) '(Radius Center)) ))) dat)) ) ;_ end of foreach (command "_.U") [color="red"](setq fn (strcat (getvar "dwgprefix") "hole dat.csv") f (open fn "w")) [color="blue"] ; If you don't want to override file ,to append use (open fn "a") as suggested by Marko @ post#14[/color] (foreach $ (foreach x dat (setq dat1 (cons (vl-string-translate " " "," (vl-list->string (vl-remove-if ''((a) (or (= a 10) (= a 40) (= a 41))) (vl-string->list x)) ) ;_ end of vl-list->string ) ;_ end of vl-string-translate dat1 ) ;_ end of cons ) ;_ end of setq ) ;_ end of foreach (write-line $ f)) (write-line " " f) (if f (close f)) (startapp "notepad" fn)[/color] [color="blue"];<--remove this line if you don't want it to pop-up everytime[/color] ) ;_ end of progn ) ;_ end of if (setvar 'cmdecho var) (princ) ) ;_ end of defun sub-functions credit to Lee Mac ;;;http://www.cadtutor.net/forum/showthread.php?35506-How-to-get-Region-coordinates/page2 ;;;adopted as sub-function (defun LM:reg (reg / RetObj) (setq Reg (vlax-ename->vla-object reg)) (if (vlax-method-applicable-p reg 'explode) (progn (setq RetObj (vlax-safearray->list (vlax-variant-value (vla-explode Reg)))) (repeat (length RetObj) (if (eq "AcDbRegion" (vla-get-ObjectName (car RetObj))) (setq RetObj (append RetObj (vlax-safearray->list (vlax-variant-value (vla-explode (car RetObj)))))) (setq RetObj (append RetObj (list (car RetObj)))) ) ;_ end of if (setq RetObj (cdr RetObj)) ) ;_ end of repeat ) ) retobj ) ;_ end of defun ;; Flatten List - Lee Mac ;; Transforms a nested list into a non-nested list ;; http://www.lee-mac.com/flatten.html (defun LM:flatten ( l ) (if (atom l) (list l) (append (LM:flatten (car l)) (if (cdr l) (LM:flatten (cdr l)))) ) ) *The overlapped circles can be filtered using x,y coordinates (2D) Edited February 7, 2015 by hanhphuc export csv Quote
magan Posted November 21, 2014 Author Posted November 21, 2014 Mr. hanhphuc, it is showing error as "error: no function definition: VLAX-ENAME->VLA-OBJECT". and one more thing that I want to ask you that, can you give me the complete single program , by which i can exactly the centres of both the circles.? Quote
hanhphuc Posted November 21, 2014 Posted November 21, 2014 add this on top [color="red"](vl-load-com)[/color][color="gray"] (defun c:test (/ i e p1 p2 ss lst q) ... ... ...[/color] Due to its 3D solid there will be 2 circles (upper & lower) for each position, difference in z value ie: 2 x 2 = 4 nos circle Quote
magan Posted November 25, 2014 Author Posted November 25, 2014 Thank you so much,,,, for your help. Its actually working. Sir, is it possible to get the radius of these circles too.? Quote
hanhphuc Posted November 25, 2014 Posted November 25, 2014 Thank you so much,,,, for your help. Its actually working. Sir, is it possible to get the radius of these circles too.? glad to help, credit to BIGAL's idea & also Lee Mac's sub-functions. yes, radius can be added updated in post #6 example output, radius is in red: CIRCLE 1: ([color="red"]1.19302[/color] (-38.7769 5.2797 2.65292)) CIRCLE 2: ([color="red"]1.19302[/color] (-38.7769 5.2797 0.0)) Quote
magan Posted November 25, 2014 Author Posted November 25, 2014 Thank you so so so much,,sir....................... It's unbelievable. I was trying for it from so many days. Thanks lot. But, when it is opened in some computer's other drawing, it just explodes whole geometry, and says: bad argument, also second problem i am facing is that sometimes it is repeating the result and counting that as circle. For example, for the 3 hole in solid, is shows 8 circles. Please help me sir, in this regard. Quote
hanhphuc Posted November 26, 2014 Posted November 26, 2014 Thank you so so so much,,sir.......................It's unbelievable. I was trying for it from so many days. Thanks lot. - you're welcome - But, when it is opened in some computer's other drawing, it just explodes whole geometry, and says: bad argument, also second problem i am facing is that sometimes it is repeating the result and counting that as circle. For example, for the 3 hole in solid, is shows 8 circles. Please help me sir, in this regard. Disadvantage of this single click method 1. ssget crossing may collect others item. 2. exploded solid contains many objects, may be it looks like a circle, it be could an ellipse? 3. we can't assure the the circle is correct hole position. im not sure repeating result. bad argument etc.. you can attach drawing. save as 2007 more generic p/s: if the hole is not tapper, can try bpoly method click on hole(s) , then ssget. It would be more accurate also can collect the rectangular center too. my $0.02 Quote
magan Posted November 26, 2014 Author Posted November 26, 2014 Oh,,, sure sir. Your help is invaluable. I will always be grateful to you as a student. Sir, if you don't mind, I want to ask you some more question which is making it difficult to use output. Sir, I am trying to get the radius and center on consecutive line. And one more thing that I want to do is, I want to save whole data in a single or separate data file (.dat). But, because our code is working on loop, the data saved in the .dat file is get over writed in the same .dat file. Means it saves only last result, not all. I am right now using this for saving the content in .dat file : (setq fo (open "D:/n_hole.dat" "w")) (princ mtw fo) (close fo) (princ) My ultimate gole of doing this is to get the number of hole, minimum diameter of hole and finally distance between all holes. Help me, if possible. Quote
marko_ribar Posted November 26, 2014 Posted November 26, 2014 Maybe, try this : (setq fo (open "D:/n_hole.dat" "[color=red]a[/color]")) "a" stands for "append"... Quote
amili Posted February 6, 2015 Posted February 6, 2015 Hey...this code is useful to me too... Thanx hanhphuc for answer and Thanx magan for this question. The problem I am facing with this code is, the data that I am saving in excel file, are not properly saved. Also, the coordinates (x y z) of centers of the circle, we get by this code are saved as single number, that just simple space between these coordinates (ex. (20 10 10)). So, I want that coordinates of center should be saved in different cells. Please help me... I need it. Quote
hanhphuc Posted February 7, 2015 Posted February 7, 2015 Hey...this code is useful to me too... Thanx hanhphuc for answer and Thanx magan for this question.The problem I am facing with this code is, the data that I am saving in excel file, are not properly saved. Also, the coordinates (x y z) of centers of the circle, we get by this code are saved as single number, that just simple space between these coordinates (ex. (20 10 10)). So, I want that coordinates of center should be saved in different cells. Please help me... I need it. hi amili welcome to CADTutor my understanding you want it to be separated for each cell? for convenient, save as csv format circle_# , Radius , X , Y , Z Updated in post #6 Quote
amili Posted February 7, 2015 Posted February 7, 2015 Thank u so much sir,,,, It is so special for me that I cannot explain it to you. Again thank you sir. If you dont mind I want to ask you some more question regading my work. As what have been done with the circular holes, can it be done with the rectangular holes? IF yes then I will have to get the following data from that rectangle: 1. Center of the rectangle 2. Points of the rectangle 3. And Length , width of the rectangle. For your refernce, I am attaching screenshot of my drawing as well as expected output excel file. It will be very much fortunate for me if these can be done with Autolisp. Please help me. Quote
sonali Posted March 3, 2015 Posted March 3, 2015 Hey Amili.... Your problem is solved, thanx to hanhphuc and lee-mac. In the post # 6, replace the AcDbCircle with AcDbPolyline. But, hanhphuc , I want to ask you one thing that, the data file which is generated continuously saves previous data, though the file is deleted. So, some previous garbage values are collected in the data fie. I want to remove those unnecessary values. Can you help in this regard?? Quote
hanhphuc Posted March 5, 2015 Posted March 5, 2015 ....the data file which is generated continuously saves previous data, though the file is deleted. So, some previous garbage values are collected in the data fie. I want to remove those unnecessary values. Can you help in this regard?? sorry for the late reply.. with (open fn "w") ;this should override the previous data. unless (open fn "a") ;this keeps appending data i'm not sure does Windows restrict it? (some pc can't even create file in directories by lisp.) Quote
sonali Posted March 5, 2015 Posted March 5, 2015 Thank you sir, for your reply. Yes sir, I have tried both "w" and "a". But, it's not working. In your program, it is not repeating the data, if we go for getting the data for circle only. But, the problem comes when, I tried to get both the polylines and circles, in two different csv files respectively. So, please help me something about it. Quote
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.