CadFrank Posted April 18, 2012 Author Share Posted April 18, 2012 Hi, well I tried changing a few things to my routine.. now I am getting a error which I do not understand Here is the error : ; error: lisp value has no coercion to VARIANT with this type: CHARGE Now here is the new routine. (defun c:grue (/ fleche charge c-p b-t) (vl-load-com) (setq charge "LC CHARGE 290") (setq c-p "LC C-P 290") (setq b-t "LC B-T 290") (if (= charge "LC CHARGE 290")(setq pt-base '(1543860.1543 165437.9249 0))) (if (= c-p "LC C-P 290")(setq pt-base '(1551739.6590 165239.6409 0))) (if (= b-t "LC B-T 290")(setq pt-base '(1564074.1763 164920.9770 0))) (initget 1 "74m 70m 64m 60m 54m 50m 44m 40m") (setq B-Radius(getkword "\n Donner le rayon de la flèche : ")) (foreach fleche '(charge c-p b-t) (setq fleche (vla-insertblock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt-base) fleche 1 1 1 0) ) ) (setq fleche (entlast)) );defun c I would just need help identifying what the error mean so i can make the corrections. Thank for the help! Quote Link to comment Share on other sites More sharing options...
ketxu Posted April 18, 2012 Share Posted April 18, 2012 You must change '(charge c-p b-t) to (list charge c-p b-t) Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 18, 2012 Author Share Posted April 18, 2012 Well it worked but now I get a new Error ; error: bad argument type: VLA-OBJECT "LC CHARGE 290" Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 18, 2012 Share Posted April 18, 2012 Your code declares the 'charge' variable as a string, not a vla-Object. ** Correction - Your code first declares 'charge' as a string, then passes 'charge' as 'fleche', which is then used as string during vla-InsertBlock, then stored as vla-Object, then stored as eName. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 18, 2012 Author Share Posted April 18, 2012 Ok I get the point, but its exactly what I want it to do so it changes the visibility state when it inserts it. So should i use repeat or something else.. I tried with apply doesnt work either.. then went to while.. but not sure how it applies. So I'm kinda of stuck now. Time for rhum Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 I would like to know if it is possible to transform if a VLA-Object can be transformed into a eName? I was dreaming about that last night .. That the error might come from there. Quote Link to comment Share on other sites More sharing options...
pBe Posted April 19, 2012 Share Posted April 19, 2012 As Renderman already pointed out. The fleche variable evolve from a string (evaluated from variable charge) to a vla-object (thru vla-insert) to a an ename (from entlast) If you're wanting to change the visibilty, you would want the inserted block as a vla-object. If you're assigning a specific base point for each block name, what do you think the value of pt-base variable inside foreach? You would think it changes for every block? it doesnt, the way your code is written now, variables charge, c-p and b-t has a non-nil value ,so all three if statements evaluates to T. which gives you the last expressions pt-base value. You can do away with those variable names and pass it directly to foreach as a quoted list HINT: (foreach itm '(("LC CHARGE 290" . (1543860.1543 165437.9249 0)) ("LC C-P 290" . (1551739.6590 165239.6409 0)) ("LC B-T 290" . (1564074.1763 164920.9770 0)) ) (print ([b]car itm[/b])) (print ([b]cdr itm[/b])) (princ) ) HTH Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 19, 2012 Share Posted April 19, 2012 I would like to know if it is possible to transform if a VLA-Object can be transformed into a eName? To answer your question, consider the vlax-Vla-Object->Ename function. I was dreaming about that last night .. That the error might come from there. I see you are enhancing your geeki-ness quite nicely... Mwaattaaahhhhaaaahhhh Separately, very well written, Pbe. ... Except for that whole part about what I pointed out; that was just a quick observation, and very 'master of the obvious' of me. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 You can do away with those variable names and pass it directly to foreach as a quoted list HINT: (foreach itm '(("LC CHARGE 290" . (1543860.1543 165437.9249 0)) ("LC C-P 290" . (1551739.6590 165239.6409 0)) ("LC B-T 290" . (1564074.1763 164920.9770 0)) ) (print ([b]car itm[/b])) (print ([b]cdr itm[/b])) (princ) ) HTH Well Thx pBe, I'm at the moment testing your hint. See how I can figure things out. I did notice that when I changed (vlax-3d-point pt-base) fleche 1 1 1 0) to (vlax-3d-point pt-base) "LC CHARGE 290" 1 1 1 0) The insertion point that was used was the last one. But thank for your hint Cheers & Beers. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 To answer your question, consider the vlax-Vla-Object->Ename function. Well Ill give it a look in my dreams tonight .. Right now im kind of busy at work hehe!! Ill keep you posted ! Thanks Quote Link to comment Share on other sites More sharing options...
pBe Posted April 19, 2012 Share Posted April 19, 2012 ...that was just a quick observation, and very 'master of the obvious' of me. A keen observant eye, you have (yoda lingo) ... well, Perfection can be achieved through repetition you see. I'm pretty sure it would help the OP with his quest as he's trying real hard to write the code and learn at the same time ... Quote Link to comment Share on other sites More sharing options...
pBe Posted April 19, 2012 Share Posted April 19, 2012 Well Thx pBe, I'm at the moment testing your hint. See how I can figure things out....Cheers & Beers. Good for you. keep it up CadFrank. you're getting there. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 So now I need to learn something else ... what does OP mean ? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 19, 2012 Share Posted April 19, 2012 So now I need to learn something else ... what does OP mean ? There are several adaptations, most commonly used for "Original Post(-er)," or the first post in a thread, or the author of... In this case, ahh you. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 Ah Weird last time I use OP i meant OVER POWERED... Those it mean.. that I'm... Quote Link to comment Share on other sites More sharing options...
CadFrank Posted April 19, 2012 Author Share Posted April 19, 2012 OMG!!! I just swallowed my bottle of rhum !!!!!! I figured it out.. Thx to both of you Renderman and pBe... So now here's the code. (defun c:grue (/ fleche B-Radius itm dbp bp) (vl-load-com) (initget 1 "74m 70m 64m 60m 54m 50m 44m 40m") (setq B-Radius(getkword "\n Donner le rayon de la flèche : ")) (foreach itm '(("LC CHARGE 290" . (1543860.1543 165437.9249 0)) ("LC C-P 290" . (1551739.6590 165239.6409 0)) ("LC B-T 290" . (1564074.1763 164920.9770 0)) ) (setq fleche (vla-insertblock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (cdr itm)) (car itm) 1 1 1 0) );setq fleche (setq dbp (vla-getdynamicblockproperties fleche)) (setq dbp (vlax-variant-value dbp)) (setq dbp (vlax-safearray->list dbp)) (setq bp (car dbp)) (setq ListeAdmis (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues bp)))) (setq ListeAdmis (mapcar 'vlax-variant-value ListeAdmis)) (vla-put-value bp B-Radius) );foreach );defun c Now all I need to do is complete my routine.. cuz this is a small part lol... And I might be able to sleep a little tonight. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted May 2, 2012 Author Share Posted May 2, 2012 ]Hi, well i'm back with a New question. I've looked on google to find some answers and got something but now I can't find it anymore.. So basicly this is what I need to do Insert a block Change 2 values. First Value is the Visibility State and this i can now do. (This goes with the section (setq radius)) (defun c:test2 (/ Tower) (setq pt1 (getpoint "\nSelect an insertion point : ")) (initget 1 "80 74 70 64 60 50 40") (setq Radius(getkword "\n Give the radius [80/74/70/64/60/50/40] : "))) (initget 1 "4 5 6 7 8 9 10 11") (setq Tower (getkword "\n Give the number of towers [4/5/6/7/8/9/10/11] : ")) (setq blk (vla-insertblock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) "LC S-M 290" 1 1 1 0) );setq blk (setq f-dbp (vla-getdynamicblockproperties blk)) (setq f-dbp (vlax-variant-value f-dbp)) (setq f-dbp (vlax-safearray->list f-dbp)) (setq f-bp (car f-dbp)) (setq f-ListeAdmis (vlax-safearray->list (vlax-variant-value (vla-get-AllowedValues f-bp)))) (setq f-ListeAdmis (mapcar 'vlax-variant-value f-ListeAdmis)) (vla-put-value f-bp Radius) ) Second Value is the TextString of the attribute. I will give you the autoCad File concerning the Block. (This goes for (setq Tower) [ATTACH]34559[/ATTACH What I know this far is that I need to change the TextString Using vla-get-TextString and vla-put-TextString I've also seen Vlax-invoke with 'attribute But since I can't find it anymore i'm seeking help here. Well this is about it. BLKtest.dwg Quote Link to comment Share on other sites More sharing options...
pBe Posted May 3, 2012 Share Posted May 3, 2012 (if (and (setq f-dbp (car (vl-remove-if-not '(lambda (j) (eq (vla-get-propertyname j) "Visibility1")) (vlax-invoke blk 'GetDynamicBlockProperties)))) (setq f-bp (member (strcat radius "m")(vlax-get f-dbp 'AllowedValues)))) (vla-put-value f-dbp (car f-bp)) ) You can even skip the member test and go directly to (vla-put-value f-dbp (strcat radius "m")) but you can never be too sure. Anyhoo What is the relevance of the variable tower?. will that be for the TAG "NB_TOUR"? What is this? ----> [ATTACH]34559[/ATTACH Quote Link to comment Share on other sites More sharing options...
CadFrank Posted May 3, 2012 Author Share Posted May 3, 2012 Hi pBe, The value of Tower is in the block attribute. The .dwg file I attached. As for the rest well it works.. But are you saying the code you posted wil do the same thing as the otherone? What is this? ----> [ATTACH]34559[/ATTACH well this is the block attachment lol... Cheers & Beers Quote Link to comment Share on other sites More sharing options...
pBe Posted May 3, 2012 Share Posted May 3, 2012 Hi pBe,The value of Tower is in the block attribute. The .dwg file I attached. As for the rest well it works.. But are you saying the code you posted wil do the same thing as the otherone? Yes. You can retrive the parameters and values directly as such in your case, where there is only one parameter and the allowed values are explicitly listed on the initget keywords and then theres only one attribute. so this line of code will work (if (setq blk (vla-insertblock (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point pt1) "LC S-M 290" 1 1 1 0) ) (progn [color=blue](setq f-dbp (car (vlax-invoke blk 'GetDynamicBlockProperties)))[/color] [color=blue] (vla-put-value f-dbp (strcat radius "m"))[/color] [color=blue] (vla-put-textstring (Car (vlax-invoke blk 'GetAttributes)) Tower)[/color] [color=blue] )[/color] ) We can include a lot of conditional expressions on the code to ensure the values are valid. For example, the Visibility parameter . it could be of a different name like "Vis1" or "Something" or the user input value of radius in not a included on the "AllowedValues" so we use (and (setq f-dbp (car (vl-remove-if-not '(lambda (j) (eq (vla-get-propertyname j) "[b]Visibility1"))[/b] (vlax-invoke blk 'GetDynamicBlockProperties)))) (setq f-bp ([b]member[/b] (strcat radius "m")(vlax-get f-dbp[b] 'AllowedValues[/b])))) 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.