BShick5088 Posted September 11, 2014 Share Posted September 11, 2014 Good afternoon, I am very new to LISP and need your help, at this point I can only make minor changes to existing code but a lot of the code still is magic to me. I have a block "ULTRA INFO" with an attribute "CIRCID" that can be used to help turn off a layer with that name that has "-DATA" added to the end. What I think we need to do is to grab the attribute variable and store it, then add a wild card * to the end, lastly have it turn off a layer with that name. Here is my thought: Some how scan the drawing for an attribute named "CIRCID" if it is found store it as "LAName" for later use. Then turn off the layer: (command "-Layer" "off" "(LAName)*" "") Any help possible is greatly appreciated. Thank you all in advance. Brian Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 12, 2014 Share Posted September 12, 2014 Do you plan to pick 1 block on screen otherwise it will find 1st occurence of the tag CIRCID and use that if not blank. Secondly (command "-Layer" "off" LAName "") you would add the * to the layer name via the lisp (setq LAName (strcat LAName "*")). Post a dwg with the block makes it easier to match 100% very easy task. Quote Link to comment Share on other sites More sharing options...
BShick5088 Posted September 12, 2014 Author Share Posted September 12, 2014 Attached is an example of one of the many drawings that will need this change. The two things that need to be done are: 1) Turn on the "SHOTS" layer, I can do this with: (Command "-layer" "O" "SHOTS" "") 2) Grab the ULTRA INFO block's CIRCID attribute add a * to it then turn off that layer. If you turn on the Shots layer you will see that a second comment is pointing to the same point showing a number and a pipe wall thickness. The company has decided to go back to the older way of showing a circle with a number that would reference an excel spreadsheet that will show a wall thickness corrosion history for each spot. Thank you so much for your help!!! Example.dwg Quote Link to comment Share on other sites More sharing options...
steven-g Posted September 12, 2014 Share Posted September 12, 2014 Can't you just use the "layoff" command and select one of the items on the layer to turn off when needed Quote Link to comment Share on other sites More sharing options...
BShick5088 Posted September 12, 2014 Author Share Posted September 12, 2014 The text and leader lines on that layer would be in different locations from drawing to drawing and I want to run this with a script file so I can apply the change to hundreds at a time without having a user do anything.If I must include a crossing pick to grab the block "ULTRA INFO" I can, at least it is in the same spot in all the drawings. "6.047,1.214" "5.689,1.291" Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2014 Share Posted September 12, 2014 I see that the "CIRCID" is a tag value and not an attribute value ! besides that there is not any layer start with this tag value in the drawing to turn it off ! Quote Link to comment Share on other sites More sharing options...
BShick5088 Posted September 12, 2014 Author Share Posted September 12, 2014 Yes, CIRCID is the tag of the ULTRA INFO block but what I need to do is get the attribute value from that tag. In the earlier example drawing the value is "H1-023" in the attached Example2 the value is "H2-020". By grabbing that value we could then concatenate the "*" or the actual end of layer name "-DATA" and be able to automatically turn off the layer. I just don't know LISP well enough to: 1) Grab the value from a block's tag. 2) Concatenate the "*" or "-DATA" to the tag's value 3) Then use that stored value to turn off the layer. I want to used the tag's value in this way because it is a reduced form of the drawing number that had been used at sometime in the past to create several layers that now need to be turned off especially the one ending with DATA. I attached a second example so you can see what I mean. Example2.dwg Quote Link to comment Share on other sites More sharing options...
steven-g Posted September 12, 2014 Share Posted September 12, 2014 How about "-layer" "off" "*-data*" the layer command accepts wildcards Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2014 Share Posted September 12, 2014 This should toggle the layer on and off depends on the status of the layer name if it is matched the value of attribute value in the target block name . Try it and let me know . (defun c:Test (/ s i l lst e n a) ;; Tharwat 12.9.2014 ;; (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "ULTRA INFO")))) (repeat (setq i (sslength s)) (mapcar '(lambda (u) (if (eq (strcase (vla-get-tagstring u)) "CIRCID") (setq lst (cons (vla-get-textstring u) lst)) ) ) (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getAttributes ) ) ) ) (if lst (while (setq a (tblnext "LAYER" (not a))) (foreach x lst (if (wcmatch (setq n (cdr (assoc 2 a))) (strcat x "*")) (entmod (subst (cons 62 (- (cdr (assoc 62 a)))) (assoc 62 (setq e (entget (tblobjname "LAYER" n)))) e ) ) ) ) ) ) (princ) )(vl-load-com) Quote Link to comment Share on other sites More sharing options...
BShick5088 Posted September 12, 2014 Author Share Posted September 12, 2014 Now that idea will work... I was so stuck in the LISP thinking a quick simple answer like that may never have occurred. You've heard "You can't see the forest for the trees.." I seem to be thinking more like "You can't see the forest for the deciduous conifers..." If anyone could still give me an example of the LISP style it will help me to understand other things that may fall more in that realm. At least for now I can finish my task. Thank you Steven, you saved my sanity!!! I know I would be banging away at this all weekend... Quote Link to comment Share on other sites More sharing options...
BShick5088 Posted September 12, 2014 Author Share Posted September 12, 2014 Thanks to Steve for pulling me out of the weeds and back on the path. Thank you Tharwat, you are a Master among men. That code you attached works perfectly!!! I can't thank you all enough!!! Have a great weekend, I will now. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 12, 2014 Share Posted September 12, 2014 Thank you Tharwat, you are a Master among men. That code you attached works perfectly!!! I can't thank you all enough!!! Have a great weekend, I will now. You're welcome . Notice that if you run the routine and the needed layer is already off , it would be on and vise versa Quote Link to comment Share on other sites More sharing options...
steven-g Posted September 12, 2014 Share Posted September 12, 2014 Glad I could help, being an LT user sometimes we need to look at things from a different angle. Have a nice weekend Quote Link to comment Share on other sites More sharing options...
Railyn Posted March 12, 2016 Share Posted March 12, 2016 Hi, sorry for hijacking your tread but I was looking to do something very similar and I was hoping you could help since you managed to solve your problem I was hoping for a lisp that automatically turns off a specific layer if a specific tag (the tag is not on that layer) is empty and turns it on again if that same tag contains information. Do you think this can be achieved with a similar kind of lisp? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 12, 2016 Share Posted March 12, 2016 I was hoping for a lisp that automatically turns off a specific layer if a specific tag (the tag is not on that layer) is empty and turns it on again if that same tag contains information. Do you think this can be achieved with a similar kind of lisp? Yes it is possible but you need to show a practical example. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 14, 2016 Share Posted March 14, 2016 Are you referring to a specific Attributed Block name or all Attributed Blocks in your drawing? If a specific one, what is the name? Quote Link to comment Share on other sites More sharing options...
Railyn Posted March 14, 2016 Share Posted March 14, 2016 It's the Tag 'HEADER6' on 'HEADER_N13' good thing you said that, a wildcard could have messed up some other sheets! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 14, 2016 Share Posted March 14, 2016 It's the Tag 'HEADER6' on 'HEADER_N13' I think you mean or and not on in your sentence , right ? I am sorry , I am not talking about wildcards but the Name of Attributed Block name(s). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 14, 2016 Share Posted March 14, 2016 Anyway try this program and let me know; (defun c:Test (/ s _t) ;; Tharwat 14.03.2016 ;; (defun _t (obj / att) (if (vl-some '(lambda (x) (and (wcmatch (strcase (vla-get-tagstring x)) "HEADER6,HEADER_N13") (setq att x)) ) (vlax-invoke obj 'getattributes) ) (vla-put-Layeron (vlax-ename->vla-object (tblobjname "LAYER" "REACTOR LAYER")) (if (eq (vla-get-textstring att) "") 0 1)) ) ) (cond ( (not (tblsearch "LAYER" "REACTOR LAYER")) (alert "Layer name <REACTOR LAYER> is not found in this drawing !") ) ( (and (princ "\nPick on Attributed Block: ") (setq s (ssget "_+.:S" '((0 . "INSERT")(66 . 1))))) (_t (vlax-ename->vla-object (ssname s 0))) ) (t (princ "\nNothing selected or selection is not attributed block !") ) ) (princ) )(vl-load-com) Quote Link to comment Share on other sites More sharing options...
Railyn Posted March 14, 2016 Share Posted March 14, 2016 I think you mean or and not on in your sentence , right ? I am sorry , I am not talking about wildcards but the Name of Attributed Block name(s). no... the block is named 'HEADER_N13' and the tag in question is 'HEADER6'... or am I being confused? sorry if I am not clear. I will try your lisp right away, thank you! 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.