lamensterms Posted May 28, 2013 Share Posted May 28, 2013 Hey guys, I’ve got this routine which I have been working on… it is a modified version of another routine which Carry helped me create for ProSteel. The philosophy behind the routine is that I will be able to hide or show ProSteel objects which have a specific type of modification. For example… If I want to show all the elements in my model which have holes drilled in them, this routine will allow me to do so. I have managed to get a reasonable working version of this routine – by doctoring the code provided to me by Carry for another exercise. There is some improvement still to be made. My current code is: (defun c:hxd (/ ss num con ent3A ent3B acadapp shapeinfo HFCs1) (vl-load-com) ;--------------------------Read Data From Bolt-------------------------------- (prompt "\nSelect ELEMENT:")(princ) (setq ss (ssget '((0 . "KS_PLATE,KS_SHAPE"))));8=Name Layer 0=ks_object (setq num (sslength ss));n° object (setq con 0) (repeat num (setq ent3A (ssname ss con)) (setq ent3B ent3A) (setq acadapp (vlax-get-acad-object)) (setq shapeinfo (vla-getinterfaceobject acadapp "PSCOMWRAPPER.Ks_ComShapeInfo")) (vlax-invoke-method shapeinfo 'setobject (vlax-ename->vla-object ent3A)) (vlax-invoke-method shapeinfo 'getinfo);ritrova le informazioni nel database (setq shapeinfo (vla-getinterfaceobject acadApp "PSCOMWRAPPER.Ks_ComShape")) (setq shapeinfo (vlax-ename->vla-object ent3B)) (setq HFCs1 (vlax-get-property shapeinfo 'HoleFieldCount)) [b](if (= HFCs1 0) (command "Ps_Hide" ent3b "") )[/b] (vlax-release-object shapeinfo) (setq shapeinfo nil) (setq acadApp nil)(princ) (setq con (1+ con)) ) ) While this routine above does perform the task I require, I would like to change how processes the selection set to hide/show. Currently the code will identify and hide all objects which have no hole modifications – working through the selection set 1 by 1. Rather than this method, I would like to add each identified element to a selection set and hide them all at once. The area of the code which I believe requires attention is highlighted in BOLD. It seems to me that this can be achieved by adding each object to a selection set, but by my understanding… I can only add to a selection set which already exists. I have very limited knowledge of how to get around this hurdle. So, I was just wondering if someone would please be able to help me come up with a solution to this puzzle. Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 28, 2013 Share Posted May 28, 2013 This addition will build a selection set from all items that were passed to PS_HIDE command; since I'm not familiar with this command, I cannot adjust the code further. ... (setq con 0) [color=magenta](setq ssetHidenItems (ssadd))[/color] (repeat num ... (if (= HFCs1 0) [color=magenta] (progn[/color] [color=magenta] (setq ssetHidenItems (ssadd ent3b ssetHidenItems))[/color] (command "Ps_Hide" ent3b "") [color=magenta] )[/color] ) ... Quote Link to comment Share on other sites More sharing options...
lamensterms Posted May 28, 2013 Author Share Posted May 28, 2013 Fantastic. Thanks so much for taking the time to reply Mircea. I understand it may be difficult to see the whole picture when the routine contains some ProSteel functions, but you got it spot on. Working code: (defun c:hxd (/ ss num con ent3A ent3B acadapp shapeinfo HFCs1 ssetHidenItems) (vl-load-com) (prompt "\nSelect ELEMENTS:")(princ) (setq ss (ssget '((0 . "KS_PLATE,KS_SHAPE"))));8=Name Layer 0=ks_object (setq num (sslength ss));n° object (setq con 0) (setq ssetHidenItems (ssadd)) (repeat num (setq ent3A (ssname ss con)) ; (entsel "\nSelect BOLT: ")) (setq ent3B ent3A) (setq acadapp (vlax-get-acad-object)) (setq shapeinfo (vla-getinterfaceobject acadapp "PSCOMWRAPPER.Ks_ComShapeInfo")) (vlax-invoke-method shapeinfo 'setobject (vlax-ename->vla-object ent3A)) (vlax-invoke-method shapeinfo 'getinfo);ritrova le informazioni nel database (setq shapeinfo (vla-getinterfaceobject acadApp "PSCOMWRAPPER.Ks_ComShape")) (setq shapeinfo (vlax-ename->vla-object ent3B)) (setq HFCs1 (vlax-get-property shapeinfo 'HoleFieldCount)) ;HoleFieldCountshape1 (if (= HFCs1 0) (progn (setq ssetHidenItems (ssadd ent3b ssetHidenItems)) ) ) (vlax-release-object shapeinfo) (setq shapeinfo nil) (setq acadApp nil)(princ) (setq con (1+ con)) ) (command "Ps_Hide" ssetHidenItems "") ) Works brilliantly. Thanks again. Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 28, 2013 Share Posted May 28, 2013 Glad I could be of help! You're entirely welcome! One observation, since you moved one statement out of the IF evaluation, there is no longer need of PROGN: (if (= HFCs1 0) [color=red] [s](progn[/s] [/color] (setq ssetHidenItems (ssadd ent3b ssetHidenItems)) [color=red] [s])[/s] [/color]) Quote Link to comment Share on other sites More sharing options...
lamensterms Posted May 28, 2013 Author Share Posted May 28, 2013 No worries Mircea, Do you agree that moviing the (command "Ps_Hide" ssetHidenItems "") line was the correct thing to do? It seemed that had I left it in the IF evaluation... the elements were still hidden 1 by 1. So by moving that line out of the IF evaluation... it allowed the PS_HIDE command to operate on 'ssetHidenItems' only once. Thanks again for the help. Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 28, 2013 Share Posted May 28, 2013 If the PS_HIDE command accepts a selection set as input, then is good that you moved it outside the cycle. Inside it will be triggered at each parse, so may be time consuming. The original code it was treating one item at a time; if you have changed it like: (if (= HFCs1 0) (progn (setq ssetHidenItems (ssadd ent3b ssetHidenItems)) (command "Ps_Hide" ssetHidenItems "") ) ) then the effect on screen were similar, but the evaluation time may be increased since it had to work on more items at a call (with one more at each cycle) even some were already hidden. Quote Link to comment Share on other sites More sharing options...
lamensterms Posted May 28, 2013 Author Share Posted May 28, 2013 Understood. Thank you for taking the time to explain. Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 28, 2013 Share Posted May 28, 2013 It was a pleasure; glad I could help! 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.