Jump to content

Recommended Posts

Posted

LT 24 and code neophyte here.
My issue is so simple that I think I don't know how to properly ask/search for a solution.

I just need to get a variable from existing TEXT entity (its contents, a number) so I can use it to figure and fill in other TEXT entities. Length and Width to fill in Area sorta stuff.
I can reliably input, operate,  and replace TEXT values from handle ids, but if I access the same item as I do with simple user fill

(setq textvalue (cdr (assoc 1 entid)))

I want this textvalue to do some math in the next line and then rtos princ that result to another existing TEXT entity. I get an error and the textvalue as the reason why.

I believe this is a type error; the item is returning as a list, not a real/int. This makes sense to me.
So I atof or atoi textvalue, but it's still not satisfied. 
I've tried simply removing the 1. from the return, but that's not it either. 

It' s frustrating because I have never programmed before, but I had a simple user input data-fill function running in 2 days (boss was impressed and I was ecstatic).
This has had me stonewalled for twice that time. Surely the pros use this kinda thing several times everyday, right?

My searches are like my cursor trying to find centerpoint in a small circle, just wiggling all around the edges. 
Thank you for reading all that.
 

Posted

Looks as though I posted this in the wrong forum. My apologies.

Posted (edited)

If you use Dumpit.lsp it will expose properties of an object, so using (vlax-get obj 'property) will return that value.

 

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick obj"))))
(setq txt (vlax-get obj 'Textstring))
(setq lay (vlax-get obj 'Layer))


(setq txt (vla-get-textstring (vlax-ename->vla-object (car  (entsel "Pick obj")))))

Then use this to convert to a number.

(setq val (atof txt))

DumpIt.LSP

 

 

Edited by BIGAL
Posted

Thank you! I set a couple hours aside tonight to dig into again. Exciting!

Is your .lsp similar to the "dumpallproperties" function? I thought "getpropertyvalue" would do the trick for me, but it did not or I wasn't using it correctly.

I'm unfamiliar with these vlax functions. Are they from a later library that was added to the autolisp standard? Visual LISP? 

I apologize for my ignorance. I'm at that stage where I'm hesitant to ask questions. I don't want to bother people for charity or worse, appear too lazy to Google. I'm in my 40s and feeling quite out of my element.

Is there a better reference for AutoLISP than the AutoDesk site itself? I bought a Udemy tutorial, but it doesn't touch on much beyond the basics. I found AfraLISP, though it's kinda hard (for me) to search through, because I don't know exactly what I'm looking for. I'm slowly working through the resources links. Mr. Lee Mac's site has been wonderful, in particular.

Too many questions.
Again, thank you so much! 

 

Posted

We all started somewhere and it is pleasant to get some interaction back from a question. Often here we see "I need a LISP that does this or that" and nothing more. So ask away and if you want to know how something works, we are all vain enough to show off what we did....

 

Post the code you have as well if you can (Not everyone can, company policies might prevent that) and we can give hints and tips along the way too.

 

 

References, here is good, The Swamp, Lee Mac and AfraLisp as well as AutoDesk for specific commands

 

Last thing, LISP has only recently been added to LT, and I don't think it has all the commands available so you might find a code but it might not work - but there are often many ways to do the same thing (See that all the time here with several different solutions to the same problem)

 

 

Alongside dump-it I use

(entget (car (Entsel "Select Entity")))

 

which prints the entity definition into the command line as a quick reference. A few more letters to type than 'Dump-it' though for the same result

Posted

Thank you for the warm welcome! I'll try not to wear it out.

My boss (the owner) has been using CAD since she was a teen, entirely without custom scripts (she's so fast). I think she'll be happy for me to figure this stuff out  for her however I have to do it (there's nothing secret in there anyway).

Solar panels on roofs. Very simple, but if I can figure out how to do this, then I can complete 3 more scripts I have partially worked out.
The handle ids are good because I use them in my one working script, same DWG. 
Here's the culprit section. 
 

; DWG References

  (setq    e60 (handent "e1d590f") ;Area reference, handle id to ename

               e63 (handent "144d0") ;ModCount ref

               edata60 (entget e60); ename to list of properties

               ModArea (assoc 1 edata60); pull second item from property list, primary value
               edata63 (entget e63)
               ModCount (assoc 1 edata63)

               OnCenters (getstring "Spacing in inches?"); script crashes after this query, 

               ModAreaR (atof ModArea); I'm trying to convert a dotted list to a real and I don't think that's how it works.

               ModCountR (atof ModCount); same here

               TotalArrayArea (rtos (* ModCountR ModAreaR) 2 0) ; PROBLEM HERE MAYBE?

  )


I'm using VSCode with the AutoLISP extension to help me check spelling and parentheses. 

Posted (edited)

1. you get dotted pair list by (assoc 1 ~~)

so, you want to play with that value. have to add (cdr ~ front of (assoc 1 ~

ModArea (assoc 1 edata60)
-> ModArea (cdr (assoc 1 edata60))
ModCount (assoc 1 edata63)
-> ModCount (cdr (assoc 1 edata63))

 

2. handle is temporary value just in that drawing.

if you want to use that routine with another drawing.

hardcoded handle name is not good.

 

3. when you use script.(.scr) don't ask to user anything is better. (getstring)

Edited by exceed
Posted

; error: bad argument type: stringp (1 . "21")

This is the error. If I am correct, it's telling me it was looking for a string, but was given a list (1 . "21").
Or it's failing a line further down on RTOS, I'm not sure.
 

Posted

Oh, didn't notice your reply. Thank you, sir!
I was thinking it had to be something along those lines.

Handle ids are temporary or enames? Both?

I'm not certain I follow the last item, not familiar with (.scr). But I'll definitely look it up. 

 

Posted

Ah, .scr doesn't allow user input. Interesting. Not sure I know how that could be of use to me yet.
The QUOTE and ' function made me feel the same way. 

I'm learning to read/write all over again. It's not supposed to be easy.
I really appreciate you guys giving your time to help me.
I taught apprentices, so I know the effort rarely pays off. And substantially less in this situation.

Posted

Handle ids are temporary or enames? Both?

 

Handle ID's are maintained within a dwg and do not change, Ent names are temporary and do change.

 

Lets go back to your 1st post, its a good idea post a dwg or an image that shows what your trying to do most times a result will occur within 24 hours.

 

What industry are you in ? This helps as some people in same industry have done a solution already.

Posted

I comment too much. 

But I wanted to say, it works! I'm not 100% sure why, but I don't have to immediately. 

Thank you everyone! 

 

(defun c:foo ()

 

  (setq e60 (handent "e1d590f") ;AREA reference

        e63 (handent "144d0") ;ModCount ref

        edata60 (entget e60) ModArea (cdr (assoc 1 edata60))

        edata63 (entget e63) ModCount (cdr (assoc 1 edata63))

        ModAreaR (atoi ModArea);

        ModCountR (atoi ModCount)

        TotalArrayArea (* ModAreaR ModCountR)

  )

 

  ;(print ModArea)

  ;(print ModAreaR)

  (print TotalArrayArea)

  (princ)

)

CDR gave the the value (thanks exceed!), but for some reason I don't understand, ATOR wasn't returning a type I could use (or so I believe).
On whim I changed it to ATOI and...it works!
Is there something about reals/floats and integers that causes this? I figured them to be mostly interchangeable. 

Posted

Hey Bigal, saw your post go up as I was typing.

We do resi solar engineering. Never occurred to me to add that to the search. Although, I'm kinda glad; it forced me to reach out to you guys. I'd like to see the ways others accomplished it. I guess I'm one of them now, sorta. Lurking here is probably a good idea.

I'm going to get my functions working first (impress the boss next meeting, ya know), then I'm going to figure out the handle id stuff. The other engineers have their own templates they use and I'm forcing them to use mine presently, so I'm sure they'd prefer I figured that out. Might not be the wisest thing and surely not the quickest, but I'm learning so much.

What you guys do is priceless, even if it's just to brag ;) 
Thank you thank you!

Posted (edited)

is this you want?

 

(defun c:foo ( / e60 e63 edata60 ModArea edata63 ModCount ModAreaR ModCountR TotalArrayArea )
  (setq e60 (handent "25B")) ;AREA reference
  (setq e63 (handent "25C")) ;ModCount ref
  (setq edata60 (entget e60))
  (setq ModArea (cdr (assoc 1 edata60)))
  (setq edata63 (entget e63))
  (setq ModCount (cdr (assoc 1 edata63)))
  (setq ModAreaR (atoi ModArea))
  (setq ModCountR (atoi ModCount))
  (setq TotalArrayArea (* ModAreaR ModCountR))
  (princ TotalArrayArea)
  (princ)
)

spacer.png

 

i mean, people usually use ssget or entsel. when doing like this

Edited by exceed
Posted (edited)

 

 

Not sure why your worrying about using Handles, I if the desired answer is to just get the text value and total.. If your text is on a layer that is a starting point for finding correct text without user input.

 

In the code (setq e60 (handent "25B")) ;AREA reference this will only work in 1 dwg as the handle id will change in each dwg you produce.

 

Again post a dwg please !!! show what you start with and what you want as a result.

 

This looks like a read a lot of 2 line text, and work out total area. Ok for me no need if your using a block for your solar cell then would use that as area is known and work out total area, based on count of common block name,  your holding back what your really trying to do, like others have done BOM with blocks, plines, circles and so on producing a table of the resulting quantities with a few hundred items involved takes seconds to produce a table. We can help.

 

Have a look at this type of automation. I am sure something can be done for solar panels.

 

 

 

Edited by BIGAL

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