TheZman Posted September 24, 2010 Share Posted September 24, 2010 Hello, I have been a lurker of the CADTutor forums for a while. I decided about a couple of days ago to dive head first into AutoLISP. Usually I like to figure things out on my own but right now by head hurts so much from banging it against the desk that I have decided to reach out for some expert advice. We have a serving area extending across 3 Township/Ranges. Each section and in some areas quarter sections is one map (drawing) So I have been trying to get a text entity at the edges of the maps so users can click on them and then click a button that runs a lisp routine that automatically xrefs the correct section into place. Here is the code I have so far. (vl-load-com) (defun C:hyperload ( / ent p1) (setq ent (entsel "\nSelect text at edge of drawing ")) (setq p1 (strcat "M:\\NewMaps\\"(vla-get-TextString (vlax-ename->vla-object (car ent))))) (command "xref" "a" p1 "0,0" "" "" "") (princ) ) (princ) The issue is when someone xrefs a map that creates a circular reference. It trys to add "0,0" to the question and errors out, becuase it needs to be yes or no. So to get around this I changed it from attach to overlay and added yes in the code. Works great IF there is a circular reference and the question to continue comes up. So how would I make the script stop and let the user input yes or no and then continue? Or How would I make the xref automatically do overlay if there is a circular reference? I have many many other questions about other things that I want to try and do. But this one is the big one right now. Thanks for any reply. Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 24, 2010 Share Posted September 24, 2010 Temporarily setting the EXPERT system variable to 5 might allow you to ignore the circular reference issue. Quote Link to comment Share on other sites More sharing options...
TheZman Posted September 24, 2010 Author Share Posted September 24, 2010 Thanks for the reply I put command expert 5 before the xref command and then back to 0 after. But circular reference issue still came up. It only really comes up if someone has saved a map with xrefs on them, which they should never do in the first place so maybe I will leave it alone for now. Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 24, 2010 Share Posted September 24, 2010 Thanks for the replyI put command expert 5 before the xref command and then back to 0 after. But circular reference issue still came up. It only really comes up if someone has saved a map with xrefs on them, which they should never do in the first place so maybe I will leave it alone for now. It was worth a shot. I'm a little curious myself; might have to do a little digging. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 24, 2010 Share Posted September 24, 2010 Just curious... Why do you have circular references? If all of your xrefs (for the maps) are xref'ed as an overlay instead of an attachment (even among themselves, i.e., quarter sections, etc.), then this issue is mute. In contrast, if your maps were xref'ed as attachments into one drawing (unloaded), you could easily use ActiveX to xref that one reference, and load/unload subsequent xrefs as selected. Regardless, *at minimum* I would use something similar to this, if you didn't want to go all out ActiveX: (defun C:hyperload (/ eName) (vl-load-com) [color=blue](if [/color](setq eName [color=blue](car [/color](entsel "\n >> Select Text at Edge of Drawing: ")[color=blue])[/color]) (command "[color=blue]._-[/color]xref" "[color=blue]_attach[/color]" (strcat "M:\\NewMaps\\" (vla-get-TextString (vlax-ename->vla-object eName))) [color=blue]'(0 0 0) 1 1 0[/color])) (princ)) Note that this still does not prevent errors if the user selects the wrong text, i.e., anything not the name of one of your maps Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 24, 2010 Share Posted September 24, 2010 *Slight* mitigation: (defun C:hyperload (/ eName dwgName dir) (vl-load-com) (if [color=red](and[/color] (setq eName (car (entsel "\n >> Select Text at Edge of Drawing: "))) [color=red](vl-position (strcase (setq dwgName (vla-get-TextString (vlax-ename->vla-object eName)))) (vl-directory-files (setq dir "M:\\NewMaps\\") "*.dwg" 1)))[/color] (command "._-xref" "_attach" (strcat dir dwgName ".dwg") '(0 0 0) 1 1 0)) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 24, 2010 Share Posted September 24, 2010 *Slight* mitigation: (defun C:hyperload (/ eName dwgName dir) (vl-load-com) (if [color=red](and[/color] (setq eName (car (entsel "\n >> Select Text at Edge of Drawing: "))) [color=red](vl-position (strcase (setq dwgName (vla-get-TextString (vlax-ename->vla-object eName)))) (vl-directory-files (setq dir "M:\\NewMaps\\") "*.dwg" 1)))[/color] (command "._-xref" "_attach" (strcat dir dwgName ".dwg") '(0 0 0) 1 1 0)) (princ)) FindFile is your friend. :wink: (defun c:Foo (/ e l n) (if (and (setq e (car (entsel "\nSelect text: "))) (member (cdr (assoc 0 (setq l (entget e)))) '("MTEXT" "TEXT")) (findfile (setq n (strcat "M:\\NewMaps\\" (cdr (assoc 1 l)) ".DWG"))) ) (command "._-xref" "_attach" n '(0 0 0) 1 1 0) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 24, 2010 Share Posted September 24, 2010 Yes, of course. Funny enough, I had written several lines of ActiveX code to respond to the OP, and only chose to post the one segment, because I felt it an important check (verifying the text picked matches one of the drawings). It was not actually written that way on my end. Edit: My original code was several lines, because I was going through the blocks collection initially. Quote Link to comment Share on other sites More sharing options...
TheZman Posted September 24, 2010 Author Share Posted September 24, 2010 Wow, thanks, you guys are awesome 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.