Michaels Posted February 28, 2011 Share Posted February 28, 2011 Hello. How can I add selection set to these codes to get a specific block(s) ? (if (setq ss (ssget "_:L" '((0 . "INSERT")))) (progn (vlax-for blocks (vla-get-blocks (setq M:cad (vla-get-activedocument (vlax-get-acad-object)))) (if (and (eq :vlax-false (vla-get-isLayout blocks)) (eq :vlax-false (vla-get-isXref blocks)) ) (vlax-for o blocks (if (wcmatch (vla-get-objectname o) "AcDbCircle") (vla-put-color o 2)) ) )) (vla-regen M:cad acActiveViewport) Many Thanks. Quote Link to comment Share on other sites More sharing options...
pBe Posted February 28, 2011 Share Posted February 28, 2011 (ssget "_x" '((0 . "INSERT")(2 . "Blockname,Blockname")));<------ your blockname/s add (66 . 1) if it includes attributes and if by chance you ran into anonymous blocks '((0 . "INSERT")(2 . "*U*,Blockname,Blockname"));<------ your blockname/s then check for Effectivename before processing the block ;; Returns list of the Anonymous names taken by a Dynamic Block (if any) - Lee Mac 2011 - www.lee-mac.com ;; Arguments: block - name of Dynamic Block. (defun AnonymousInstancesof ( block / def rec nme ref lst ) (while (setq def (tblnext "BLOCK" (null def))) (if (= 1 (logand 1 (cdr (assoc 70 def)))) (progn (setq rec (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" (setq nme (cdr (assoc 2 def)))) ) ) ) ) ) (while (setq ref (assoc 331 rec)) (if (and (eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref)))) (not (member nme lst)) ) (setq lst (cons nme lst)) ) (setq rec (cdr (member (assoc 331 rec) rec))) ) ) ) ) (reverse lst) ) Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 28, 2011 Share Posted February 28, 2011 FYI, the "_:L" portion of your ssget selection is to filter objects on locked layers. I keep noticing other people posting code that includes this filter when it is not needed. Just wanted to make sure you actually understood it instead of using it blindly. Quote Link to comment Share on other sites More sharing options...
Michaels Posted February 28, 2011 Author Share Posted February 28, 2011 FYI, the "_:L" portion of your ssget selection is to filter objects on locked layers. I keep noticing other people posting code that includes this filter when it is not needed. Just wanted to make sure you actually understood it instead of using it blindly. Thanks. I do know that it is for filtering Locked layers and I got used it to it because it is important . Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 28, 2011 Share Posted February 28, 2011 Thanks. I do know that it is for filtering Locked layers and I got used it to it because it is important . but not always needed. :wink: Quote Link to comment Share on other sites More sharing options...
Michaels Posted February 28, 2011 Author Share Posted February 28, 2011 but not always needed. :wink: Now it is new to me. Quote Link to comment Share on other sites More sharing options...
Michaels Posted February 28, 2011 Author Share Posted February 28, 2011 (ssget "_x" '((0 . "INSERT")(2 . "Blockname,Blockname")));<------ your blockname/s add (66 . 1) if it includes attributes and if by chance you ran into anonymous blocks '((0 . "INSERT")(2 . "*U*,Blockname,Blockname"));<------ your blockname/s then check for Effectivename before processing the block ;; Returns list of the Anonymous names taken by a Dynamic Block (if any) - Lee Mac 2011 - www.lee-mac.com ;; Arguments: block - name of Dynamic Block. (defun AnonymousInstancesof ( block / def rec nme ref lst ) (while (setq def (tblnext "BLOCK" (null def))) (if (= 1 (logand 1 (cdr (assoc 70 def)))) (progn (setq rec(entget(cdr(assoc 330(entget(tblobjname "BLOCK" (setq nme (cdr (assoc 2 def))))))))) (while (setq ref (assoc 331 rec)) (if (and (eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref)))) (not (member nme lst))) (setq lst (cons nme lst))) (setq rec (cdr (member (assoc 331 rec) rec))))))) (reverse lst) ) Great work pBe. thank you so much. But that's not what I am looking forward . As you for sure know that the second part of my codes is to change the color of circles in Block Definitions , but I want to change the color of circles in the selected Blocks only by the use of "ssget" to be able to select two to three blocks at the same time . Appreciated a lot. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 28, 2011 Share Posted February 28, 2011 (edited) Lol what's with the 'M:CAD' (you) or 'TH:CAD' (Tharwat) for your variables? You guys must think the same way... [or are the same person] Back to the original question - Note that you won't be able to change specific Inserts since you are modifying the block definition - which will be applied to all Inserts for that definition. You will need to add a filtered selection using ssget, perhaps with the DXF Group 2 as pBe correctly states, then, when iterating through the set, check that you haven't already processed the block name by checking against a list of processed block names, and if not, retrieve the block definition and perform your modifications, then when done, add the block name to the list of blocks already processed. Lee Edited February 28, 2011 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Michaels Posted February 28, 2011 Author Share Posted February 28, 2011 I am sorry , it's not clear enough yet. many thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 28, 2011 Share Posted February 28, 2011 I am sorry , it's not clear enough yet. Which part isn't clear? Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 28, 2011 Share Posted February 28, 2011 Which part isn't clear? The part you didn't code for him. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 28, 2011 Share Posted February 28, 2011 The part you didn't code for him. Most likely. I'm still puzzled by this.. what's with the 'M:CAD' (you) or 'TH:CAD' (Tharwat) for your variables? Quote Link to comment Share on other sites More sharing options...
Michaels Posted March 1, 2011 Author Share Posted March 1, 2011 (edited) Lee . My poor experience with lisp forced me to copy and paste things like that sometimes . And what is the logic of these Men's codes ? (defun HSN:...... () ; @ HasanCAD .......... ...... (KDUB:ucs:Move_X)) ...... ... (defun LM:grX ( p s c / -s r q ) ;; © Lee Mac ..... ........... .......... (and TH:UnDo (vla-EndUndoMark TH:CAD)) ....... Is it one man way or experts' way ? I promise you that I would get my won way when I become at least able to write small routine . Michaels Edited March 1, 2011 by Michaels Quote Link to comment Share on other sites More sharing options...
pBe Posted March 1, 2011 Share Posted March 1, 2011 This makes it easy to determine functions that have been developed by you in support of the main code -Good Habits for Coding in Visual LISP® - Robert Bell - Quote Link to comment Share on other sites More sharing options...
Michaels Posted March 1, 2011 Author Share Posted March 1, 2011 This makes it easy to determine functions that have been developed by you in support of the main code -Good Habits for Coding in Visual LISP® - Robert Bell - I did not get the point well ! Quote Link to comment Share on other sites More sharing options...
pBe Posted March 1, 2011 Share Posted March 1, 2011 In programming in general. its always a good practice to make names of routines as long as necessary that clearly describes everything the routine does (a description of the return value) as for adding the prefix... i.e (defun LM:WhatMyFunctionIs ) These prefixes may help you when posting code on forums or discussion groups for support. As you get ready to post your code you may notice those toolbox functions due to their prefix and include those external functions. This makes it easier to get support. now as for this.. what's with the 'M:CAD' (you) or 'TH:CAD' (Tharwat) for your variables? Beacuse those prefix are normally associated with routine names and not for variable names. now variable naming convention is another thing.. simply put. its a good practice for programemrs all over the world to follow. you dont have to do this is what i'm trying to tell you.. but then again,... see previous post Hope this helps Quote Link to comment Share on other sites More sharing options...
Michaels Posted March 1, 2011 Author Share Posted March 1, 2011 Exactly pBe. But for me as a beginner of Lisp , I am trying to get used to things that most of excellent programmers do . So that's why I have been trying to use some of others' ways of handling things like that . Greatly appreciated pBe. Thank you . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 1, 2011 Share Posted March 1, 2011 Since you aren't willing to give it a try, or indicate which part of my explanation wasn't clear, here is an example for you to copy/paste into your code whilst still not understanding its inner workings: [color=RED]([/color][color=BLUE]defun[/color] [color=black]c:test[/color] [color=RED]([/color] [color=BLUE]/[/color] acdoc acblk acsel name done [color=RED])[/color] [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color] [color=#990099];;---------------------------------------------;;[/color] [color=#990099];; Example © Lee Mac 2011 - www.lee-mac.com ;;[/color] [color=#990099];;---------------------------------------------;;[/color] [color=RED]([/color][color=BLUE]setq[/color] acdoc [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED]))[/color] acblk [color=RED]([/color][color=BLUE]vla-get-Blocks[/color] acdoc[color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]ssget[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"INSERT"[/color][color=RED])))[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]vlax-for[/color] block [color=RED]([/color][color=BLUE]setq[/color] acsel [color=RED]([/color][color=BLUE]vla-get-ActiveSelectionSet[/color] acdoc[color=RED]))[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]member[/color] [color=RED]([/color][color=BLUE]setq[/color] name [color=RED]([/color][color=BLUE]vlax-get-property[/color] block [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]vlax-property-available-p[/color] block [color=DARKRED]'[/color]effectivename[color=RED])[/color] [color=DARKRED]'[/color]effectivename [color=DARKRED]'[/color]name [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] done [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]progn[/color] [color=RED]([/color][color=BLUE]vlax-for[/color] obj [color=RED]([/color][color=BLUE]vla-item[/color] acblk name[color=RED])[/color] [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]eq[/color] [color=#a52a2a]"AcDbCircle"[/color] [color=RED]([/color][color=BLUE]vla-get-Objectname[/color] obj[color=RED]))[/color] [color=RED]([/color][color=BLUE]vla-put-color[/color] obj [color=BLUE]acred[/color][color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]setq[/color] done [color=RED]([/color][color=BLUE]cons[/color] name done[color=RED]))[/color] [color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]vla-delete[/color] acsel[color=RED])[/color] [color=RED]([/color][color=BLUE]vla-regen[/color] acdoc [color=BLUE]acallviewports[/color][color=RED])[/color] [color=RED])[/color] [color=RED])[/color] [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color] [color=RED])[/color] Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 2, 2011 Share Posted March 2, 2011 ...................... 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.