TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Water Bear on January 05, 2004, 01:23:25 PM
-
I'm numbering duct pieces on a drawing, but when I resume the drawing my lisp function begins counting all over (repeated numbers). Can anyone tell me how I can retrieve the last number used, and continue incrementing by one?
-
You might start by showing us the lisp routine you're using.
-
You might start by showing us the lisp routine you're using.
Yup.
-
(defun CNT ()
;;;need to search drawing for highest number and set to #CNT
;;;I put this in to keep from crashing on undefined variable
(if #CNT
nil
(setq #CNT 0)
)
(setq #CNT (1+ #CNT))
(princ)
)
(princ)
-
Ok WATER BEAR, when exiting a drawing, all variables that have been assigned are gone. When you load the drawing and try and find the #CNT they are not there. Am I going in the right direction for you? If not, maybe you should post ALL the code.
-
Try this....
(defun CNT ()
(if #CNT
nil
(setq #CNT (getvar "USERI1"))
)
(setq #CNT (1+ #CNT))
(setvar "USERI1" #CNT)
(princ)
)
Problem solved....
Cool huh
-
DGC..you've got it.
The only reason that I didn't post all the code is because I've separated it into four files which I load as a project..and it probably wouldn't make sense without showing the utilities,error traps and I/O routines.
what I need to do is re-establish the last number, probably using tblsearch..but I don't know how to collect all text objects on layer "pc numbers" then find the highest value.
-
Check yer fire, check yer fire!
You've got a variable conflict here.
USERI1 or USERR1?
-
what I need to do is re-establish the last number, probably using tblsearch..but I don't know how to collect all text objects on layer "pc numbers" then find the highest value.
Storing the number in a seperate file out of the question?
-
Use use ssget "x" function to collect all text objects on the layer, then iterate through them, creating a list. Then use the LAST function to find the highest value. I'm not going to write this for you, you'll have to do it yourself. I will help if you should so ask me for it nicely.
-
Where......:P
-
What's the text? Is it all going to be a number or is there going to be some text included.
like: Type 'A' 123
-
OK, ok I'll help.
I use this for REVISION TRACKING...
(setq lastrev (acad_strlsort (list isrev3-1 isrev7 isrev10 isrev13)))
(setq lastrev (last lastrev))
(setq lastrevdate
(cond
((= lastrev isrev3-1) isrev5-2)
((= lastrev isrev7) isrev6-2)
((= lastrev isrev10) isrev7-2)
((= lastrev isrev13) isrev8-2)
)
)
keep in mind that I set up the values for isrev?-? ahead of time.
-
Uhh, you might also want to mention what version of acad you're using as anything pre-2000 won't allow things like vl-sort.
-
The acad_strlsort function is alphnumeric, alieviating the need to pick apart the string for its numeric content.
-
So, my spelling aint so good, umm, yes, what is your operating status Mr. Water Bear?
AutoCAD version?
Operating System?
-
Perhaps something like this would suit ?
kwb
(defun nextductid (/ returnvalue)
(or #cnt (setq #cnt (getcfg "appdata/MySTUFF/LastDuctID")))
(or (and #cnt (/= 0 (strlen #cnt)))
(setq returnvalue (getint "No Duct Number has been saved. Enter New Number :"
)
returnvalue (if (= returnvalue "")
000
(1- returnvalue)
)
)
)
(if (numberp returnvalue)
(setq #cnt (itoa(1+ returnvalue)))
(setq #cnt (itoa(1+ (atoi #cnt))))
)
(setcfg "appdata/MySTUFF/LastDuctID" #cnt)
#cnt
)
-
Kerry, I actually had thought of using that scenario, but if there are multiple drawings, the duct number would be incorrect in a different drawing. I suggest using the system variable USERI1 to store the number since it is an integer and is stored in the drawing when it is saved.
-
Oh, sure just give him the whole farm. How will people ever learn to be responsible Lispers if they never learn on their own?
Keb, if another routine uses the USER??? variables when a drawing is opened, he's not going to aquire the correct info from it. The CORRECT way would be the sort through method.
-
DGCs..thanx, let me work on the ssget "x"
p.s. I noticed right away KEB wuz pulling a chain...hater!
-
Huh????I aint pullin no ones chain....I aint got no hands....If'n ya don't want to just replace yer cnt code with my edited one that's fine cuz I just like to code....
an wazzup with hater????
-
Perhaps this then
(setcfg (strcat "appdata/MySTUFF/" (getvar "dwgname") "/LastDuctID") "123")
(getcfg (strcat "appdata/MySTUFF/" (getvar "dwgname") "/LastDuctID"))
< added >
Keith ... its just that I loath the "USERxxx" vars :)
-
Huh????I aint pullin no ones chain....I aint got no hands....If'n ya don't want to just replace yer cnt code with my edited one that's fine cuz I just like to code....
an wazzup with hater????
I was wondering the same thing. Guy don't know what he's talking about, I think.
-
Ok, Kerry ... just being the devils advocate for a minute.. what happens when he has edited like a thousand drawings....the acad.cfg gets HUGE, plus the drawing cannot be edited across machines effectively...
If you don't like USERxx variables that is ok.. I was simply trying to offer the simplest solution to the problem..
But...
We can still have an internal count (internal to the drawing) that is editable by the program across multiple edits and on different machines at the same time...
(defun CNT ()
(vl-load-com) ; per the Daron Act
(if #CNT
nil
(if (not(setq #CNT (vlax-ldata-get "DuctCount" "CNT")))
(setq #CNT 0)
)
)
(setq #CNT (1+ #CNT))
(vlax-ldata-put "DuctCount" "CNT" #CNT)
(princ)
)
Now how is that.....totally portable, usable on R2000+, no external files and simple.
-
Sorry if I step on any toes..I thought someone was INTENTIONALLY misdirecting me because of inconstistent "USERI1" variables...but the post has since been corrected..my bad, I should have known it was an innocent typo! my apologies to KEB
DGCs:2k4 XP
-
Keith :: Yep that works cool.
what's that expression about lots of ways to pluck a duck :D
An effective solution depends on the project requirements, which we dont know of course.
Personally I would use attributed blocks, then a search is easier, and so is renumbering if you have to.
-
KerryB
That sounds like an interesting alternative (attributes) how would I setup to re-number? What function could I use?
-
I like ldata. (I always forget about it too!) I like the idea of an external file, but thats cool. whatever works.
-
how would I setup to re-number? What function could I use?
WB, you would need to use attributed blocks for your numbering scheme, even if it is simply a single attribute with no other objects. You could then filter for the block name and each one would have a unique number. Once the selection of the blocks is completed, you would simply need to use other routines available from this site to update and/or change the numbering.
-
How about using xdata. Attach xtended entity data to the entities in question. If they are text entities all the better, just find em and manipulate em.
Quack.
-
Xdata can be difficult to master, I seldom use it, but to each 'is own
-
This area is new to me, but could you use a block to store the last entered number
leaving all labels as text. I suppose the block could be on a Non-plotting layer
or hidden somehow?
CAB
-
> or hidden somehow?
How about
vlax-put-property obj 'Visible :vlax-false
-
There you go... another ingenious way to solve a problem....insert a single block with a single attribute in the drawing, make it invisible, then simply search for and extract that and update that block data as needed.
Well, I know there was a more than one way to skin a cat....fish that is...
-
Use use ssget "x" function to collect all text objects on the layer, then iterate through them, creating a list.
I think deegeecees has the only worth while solution to this problem. Imagine someone missing to order 50 duct pieces just because someone forgot to run a lisp routine? Not good.
Run through all the existing numbers, decide which is the most recent and start counting from there on. Whether it is text, mtext, attribute info or whatever holding the numbers. Reorganize the drawings if needed - put numbers on unique layers, in unique attributes or attach a signature as xdata saying it is a duct number. Doesn't matter, but don't save the last count anywhere! Get the last count fresh from the bakery each time you need to add a count.
-
Stig, the original request was that the lisp that WB had would not retrieve the last number used, we were simply trying to fix an otherwise fine lisp by having it retrieve and store the last number used.
There are merits to any system used, but no matter how you look at it, somewhere someone MUST run a lisp, vba or macro and since the lisp is what will number the duct pieces, the user cannot simply "forget" to run it, to do so would be to "forget" to do their job in the first place.
I know there were at least 5 good solutions to this scenario the job of deciding which to use is up to WB, that is why we have a forum to get everyones input.
-
I think Stig has a point.
Also: What are you gonna do if someone decides to copy a section of duct with hidden xdata? They run the app and the app starts off with a huge number. I am begining to think that saving the info anywhere but in the entity itself is a bad thing. (I can already see quite a bit of info being stored in that object.)
...This had better get drawn out, cuase this could get messy!
-
Stig, the original request was that the lisp that WB had would not retrieve the last number used.
Keith, you're correct. And I say, retrieve the last number, not by saving it, but by counting to it.
.. somewhere someone MUST run a lisp, vba or macro and since the lisp is what will number the duct pieces, the user cannot simply "forget" to run it, to do so would be to "forget" to do their job in the first place.
True, but consider this:
1. Get last count from saved static data
2. Increment number
3. Click at duct piece to add number
4. Go to 2. until done
5. Save last count as static data
Splendid. Now do as users always do: hit Escape at no. 3. Replace no. 4 with 5? Hit escape somewhere else.
Use USERxx or LData? Load another app that overwrites it. Use Dicts? Lost if wblocked. Use XData? Hit Esc at the wrong place and it's out of sync. Use external file? Out of sync on different stations. Just too risky to save a single number somewhere if it can be retrieved on the fly. One could even put a verifier into the code to report errors in existing sequences.
-
count each time?! ...Yeah i see your point Stig.
-
Yeah well, count each time you need a number to count from, i.e. each time the routine is run :)
-
Sure, considering user variables can be changed by anybody at any time.
-
Stig...point taken, and it is a very valid point, WB will simply have to ensure that a standard is adhered to when applying numbers to ducts. If a routine is going to retrieve all of the duct numbers, the duct numbers must be identified by either xdata, a special layer, textstyle, blockname or other uniquely identifiable trait that can be filtered for. This is where a drawing standard will come in... I think we all understand the importance of standards...Now it is simply a matter of getting the information from WB as to what he would like to do.
-
While your at it how about
Report any missing numbers
CAB