Jump to content

Look up and visibility


CadFrank

Recommended Posts

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!

Link to comment
Share on other sites

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

  • CadFrank

    40

  • ReMark

    9

  • BlackBox

    9

  • pBe

    7

Top Posters In This Topic

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.

Link to comment
Share on other sites

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 8)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :thumbsup:

 

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 :geek:

 

 

Separately, very well written, Pbe. :thumbsup: ... Except for that whole part about what I pointed out; that was just a quick observation, and very 'master of the obvious' of me. :rofl:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

...that was just a quick observation, and very 'master of the obvious' of me. :rofl:

 

A keen observant eye, you have (yoda lingo) :lol: ... 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 ... :thumbsup:

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

]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

Link to comment
Share on other sites

(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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]))))

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...