pman860507 Posted April 28, 2012 Posted April 28, 2012 I have a command that allows me to make an arc from the center of the block which is a circle. After the the arc is made I want it to trim out the arc that is block using the block as the object and the starting point of the arc as the the object to trim. This all works perfectly if the point is in the visible window. If you pan out of the area where you can no longer see the point you get a hatched window. This is annoying because it kills the command. Is there any way to get this to work when dont see the starting point? Below is a section of the code that actually does a rectangle. Starts the arc at the mid between 2 corners. The other part is a lot longer so i will just leave it out for now. Since i had to added a zoom feature to bypass this issue for now. (while (= square nil) (setq square (entsel "\nSelect Light or Juncion box:"))) (cond ((/= square nil) (setq sq (entget (car square))) (setq pnt(list)) (setq blkType(cdr(assoc 0 sq))) (setq BlkName(cdr(assoc 2 sq)))) ((= square nil) (setq blktype "NOTHING") (princ "\nNo Objects Selected."))) (cond ((= blkType "LWPOLYLINE") (foreach a sq (if(= 10 (car a)) (setq pnt (append pnt (list(cdr a)))))) (setq p1 (nth 0 pnt)) (setq p2 (nth 2 pnt)) (setq npnt (mapcar '/ (mapcar '+ p1 p2) '(2.0 2.0 2.0))) (command "arc" npnt pause pause) (setq ar (entlast)) (command "trim" square "" npnt "")) Thanks. Quote
MSasu Posted April 28, 2012 Posted April 28, 2012 It is not recommended to use edit commands like TRIM or FILLET in AutoLISP routines since the results can be influenced by the zoom level or the edit area visibility. I suggest you to add that arc (seems that the action require user’s intervention) and later calculate the insertion point between circle and arc (check those tools from Lee Mac’s library) and either use ENTMODE to fix the arc or erase it and redraw from intersection point using the features of first one. Quote
pman860507 Posted April 29, 2012 Author Posted April 29, 2012 Thanks, I think the fact that its so early here that i just completely miss read the post 3 or 4 times lol. This is a genius idea. I will work on it either today or monday and let you know how it turns out thanks a lot. -EDIT- I forgot to add that LEE is amazing. Thanks for all your hard work. Quote
pman860507 Posted May 1, 2012 Author Posted May 1, 2012 (edited) So i finally got a little bit of time to look over the intersection code but am using the examples atm that LEE provides just seeing how it work. and the issue im having is its not working currently I'm using a circle and a line that are intersecting with these too commands. From here link ;; ;; ;; Returns a list of all points of intersection between ;; ;; two objects ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; obj1, obj2 - VLA-Objects ;; ;;------------------------------------------------------------;; ;; Returns: List of intersection points, or nil ;; ;;------------------------------------------------------------;; (defun LM:GetIntersections ( obj1 obj2 ) (LM:GroupByNum (vlax-invoke obj1 'IntersectWith obj2 acExtendNone) 3) ) Then I'm running this command. (defun c:test1 ( / e1 e2 ) (vl-load-com) (if (and (setq e1 (car (entsel "\nSelect First Object: "))) (setq e2 (car (entsel "\nSelect Second Object: "))) ) (foreach x (LM:GetIntersections (vlax-ename->vla-object e1) (vlax-ename->vla-object e2)) (entmakex (list (cons 0 "POINT") (cons 10 x))) ) ) (princ) ) I was getting a :CALLBACK-ENTRY, in last break source. So i defined this error handler ( defun *error* (s) (vl-bt) (princ) ) I received this in the command prompt after. Command: test1 Select First Object: Select Second Object: Backtrace: [0.65] (VL-BT) [1.61] (*ERROR* "no function definition: LM:GROUPBYNUM") LAP+7 [2.55] (_call-err-hook #<USUBR @25e9fbb8 *ERROR*> "no function definition: LM:GROUPBYNUM") [3.49] (sys-error "no function definition: LM:GROUPBYNUM") :ERROR-BREAK.44 "no function definition: LM:GROUPBYNUM" [4.41] (#<SUBR @1e4a45b4 null-fun-hk> (4815.92 1966.46 0.0) 3) [5.36] (LM:GROUPBYNUM (4815.92 1966.46 0.0) 3) [6.30] (LM:GETINTERSECTIONS #<VLA-OBJECT IAcadLine2 19a79e0c> #<VLA-OBJECT IAcadCircle2 19a79da4>) LAP+31 :XTSF-MARK.23 (FOREACH nil #<SUBR @1efac7d0 nil> (Rest-List X)) [7.20] (C:TEST1) LAP+132 [8.15] (#<SUBR @25e9fbe0 -rts_top->) [9.12] (#<SUBR @1e4a435c veval-str-body> "(C:TEST1)" T #<FILE internal>) :CALLBACK-ENTRY.6 (:CALLBACK-ENTRY) :ARQ-SUBR-CALLBACK.3 (nil 0) I have no idea what that means. So am i doing something wrong? Thanks all. Edited May 1, 2012 by pman860507 Quote
Lee Mac Posted May 1, 2012 Posted May 1, 2012 pman, Firstly, thank you for your appreciation and gratitude for my work. Secondly, please read carefully the Terms of Use applicable to all code published on my site, I would appreciate if you retained all headers included with my code (please edit your earlier post), and use a link to reference the original code where possible. Now, to solve your problem, note that all of the Intersection functions require my Group by Number function, which is included at the end of the first code pane on the program page. Lee Quote
pman860507 Posted May 1, 2012 Author Posted May 1, 2012 (edited) Sorry about that LEE everything should be updated. I was just doing a quick copy and paste from the site before break I didn't even realized it. I also don't know why i can't ever get the code to go multi line. anyways. It worked. Thanks a lot. If the object is a block will this not work? Edited May 1, 2012 by pman860507 update Quote
Lee Mac Posted May 1, 2012 Posted May 1, 2012 Sorry about that LEE everything should be updated. I was just doing a quick copy and paste from the site before break I didn't even realized it. I also don't know why i can't ever get the code to go multi line. anyways. It worked. Thanks a lot. Thank you pman, appreciated. Regarding loss of line breaks, are you copying the code to another editor (such as WordPad, for example) before posting to the forum? Quote
pman860507 Posted May 1, 2012 Author Posted May 1, 2012 No i was copying it right off your site. The error code came straight from autocads command prompt. Guess i have one more question when I'm using and arc and a circle block (circle changes depending on the scale of the drawing). the point is 1/2" off when its at full scale. and gets smaller off the smaller the scale gets. should i be using a different Intersection command? I should add that each of these will be and arc and a circle block. The circle block is entity will be pulled out of a list (used ssget) then (entget). The arc is also an entity from when it's created. Quote
Lee Mac Posted May 1, 2012 Posted May 1, 2012 No i was copying it right off your site. The error code came straight from autocads command prompt. If you copy the code to an editor first, such as Notepad or the VLIDE, then copy to the forum editor, the line breaks should remain in-tact. The problem occurs because when copying directly from my site (or any site), the CSS formatting is copied also, and is then removed (along with line breaks) when used in the forum post editor. If the object is a block will this not work? The VLA Block Reference Object does have an IntersectWith method (the method that is invoked by my functions), however, in my experience, I have found the method to be temperamental when used with Blocks, sometimes producing unexpected results. I would suggest using the Explode method on the VLA Block Reference Object, which will return a variant of exploded objects whilst leaving the original Block Reference Object in place. You can then use my functions on objects within this variant, before deleting the exploded objects. Quote
pman860507 Posted May 1, 2012 Author Posted May 1, 2012 Well thats way above me. Im not a VLA person. I think i might just have it create a circle around the block then remove it after the intersection is found. Maybe thats a dumb idea. Who know getting ready to head to school though so it will have to wait till tomorrow. Thanks for the tip about the coping the code to an editor first. Looks great now. Quote
Lee Mac Posted May 1, 2012 Posted May 1, 2012 Well thats way above me. Im not a VLA person. I think i might just have it create a circle around the block then remove it after the intersection is found. Maybe thats a dumb idea. Who know getting ready to head to school though so it will have to wait till tomorrow. Here is an example for you to study which demonstrates the methods I have described, I hope I have explained it clearly: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] circleobj entity1 entity2 explodedobjects ) [color=GREEN];; Define function and localise variables[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following returns a non-nil result[/color] ([color=BLUE]and[/color] [color=GREEN];; If all of the following expressions return a non-nil result[/color] ([color=BLUE]setq[/color] entity1 ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect First Object: "[/color]))) [color=GREEN];; Get first entity[/color] ([color=BLUE]setq[/color] entity2 ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect Block containing Circle: "[/color]))) [color=GREEN];; Get second entity[/color] ([color=BLUE]eq[/color] [color=MAROON]"INSERT"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] entity2)))) [color=GREEN];; Check that second entity is a Block[/color] ) [color=GREEN];; End AND[/color] ([color=BLUE]progn[/color] [color=GREEN];; Wrap the following into a single expression[/color] ([color=BLUE]setq[/color] explodedobjects ([color=BLUE]vlax-invoke[/color] ([color=BLUE]vlax-ename->vla-object[/color] entity2) 'explode)) [color=GREEN];; Explode the block:[/color] [color=GREEN];; I have used the undocumented 'vlax-invoke' so that the Explode method[/color] [color=GREEN];; returns data in the native AutoLISP data types, to avoid having to manipulate[/color] [color=GREEN];; SafeArrays & Variants.[/color] [color=GREEN];; If the block contains a circle...[/color] ([color=BLUE]if[/color] [color=GREEN];; If the following returns a non-nil result[/color] ([color=BLUE]setq[/color] circleobj ([color=BLUE]car[/color] [color=GREEN];; First item of the returned list (may be nil)[/color] ([color=BLUE]vl-member-if[/color] [color=GREEN];; Returns the item and remainder of the list when an[/color] [color=GREEN];; item meets the conditions set by the predicate function:[/color] '([color=BLUE]lambda[/color] ( obj ) ([color=BLUE]eq[/color] [color=MAROON]"AcDbCircle"[/color] ([color=BLUE]vla-get-objectname[/color] obj))) explodedobjects ) [color=GREEN];; End VL-MEMBER-IF[/color] ) [color=GREEN];; End CAR[/color] ) [color=GREEN];; End SETQ[/color] [color=GREEN];; Foreach point of intersection (may be none) between selected entity[/color] [color=GREEN];; and Circle from within block (already a VLA-Object):[/color] ([color=BLUE]foreach[/color] point (LM:GetIntersections ([color=BLUE]vlax-ename->vla-object[/color] entity1) circleobj) [color=GREEN];; Create Point entity at intersection point[/color] ([color=BLUE]entmake[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"POINT"[/color]) ([color=BLUE]cons[/color] 10 point))) ) [color=GREEN];; End FOREACH[/color] ) [color=GREEN];; End IF[/color] [color=GREEN];; Delete temporary exploded objects:[/color] ([color=BLUE]foreach[/color] object explodedobjects ([color=BLUE]vla-delete[/color] object) ) [color=GREEN];; End FOREACH[/color] ) [color=GREEN];; End PROGN[/color] ) [color=GREEN];; End IF[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Exit Cleanly[/color] ) [color=GREEN];; End DEFUN[/color] ([color=BLUE]vl-load-com[/color]) [color=GREEN];; Load Visual LISP functions[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Load Cleanly[/color] Thanks for the tip about the coping the code to an editor first. Looks great now. You're welcome Quote
pman860507 Posted May 4, 2012 Author Posted May 4, 2012 Well Lee thanks a lot. I had to change a few things to make it all work exactly how i needed it to all the comments where awesome for editing it. I got it all working exactly how i needed it too. Thanks a lot. Quote
Lee Mac Posted May 4, 2012 Posted May 4, 2012 Excellent to hear it was beneficial for your learning, you're welcome 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.