Pbejse Lisp Edit / Guidance

Pbejse Lisp Edit / Guidance

Anonymous
Not applicable
1,688 Views
25 Replies
Message 1 of 26

Pbejse Lisp Edit / Guidance

Anonymous
Not applicable

Hi,

 

I'm not sure if I should have posted in the old thread or created a new one so apologies if I've gone about this the wrong way.

 

I was looking for a LISP routine that sequentially numbers attributes and I noticed one posted by pbejse Here.

 

This is so close to being exactly what I'm looking for but I would like the lisp to sequentially number based on varying text (example below).  The above lisp specifies whether the contained text string should be "ELEVATION" or "ADDRESS" whereas I have many variables.

 

Attribute Tag: NUMBER

Attribute Value: (Varies) - Door, Window, Wall, Chair, Table, etc

Required Output: Door1, Door2, Door3, Window1, Window2, Chair1, Chair2, Chair3, Table1, etc

 

I'm not skilled enough to change this lisp myself, nor do I want to do so without permission from the author.

 

Would anyone be able to assist with this?

 

Thanks in advance!

0 Likes
Accepted solutions (1)
1,689 Views
25 Replies
Replies (25)
Message 21 of 26

pbejse
Mentor
Mentor

 

First lets analyze the content of attval variable
    (("ID" "Big Beige Bay Window" #<VLA-OBJECT )("TAG2" "10x25x12" #<VLA-OBJECT ))
    

((not (setq id (assoc "ID" attval)))) ; Set "id" equal to the "ID" attribute 
value line means if "ID" is indeed a part of attval list, in this case YES
--> ("ID" "Big Beige Bay Window" #<VLA-OBJECT ) Then the line will evaluate to nil and continue with the next
condition statement Value of variable id ( "ID" <-- car "Big Beige Bay Window"<-- cadr #<VLA-OBJECT <-- caddr ) (caddr id);<-- 3rd element in this case the value for that line is the third element
of the list which is the vlaobject --> #<VLA-OBJECT (setq f (assoc (strcase (cadr id)) mlst)) here the function strcase converts the value from (cadr id)
---> "Big Beige Bay Window" to uppercase letters assoc will test if the value from above is already included
on the variable mlist < more on this below > If the above statement is true then do the items below.
say value for f is a dotted pair ("Big Beige Bay Window" . 2) (strcat --> string concantenate function (cadr id) --> "Big Beige Bay Window" (itoa --> Convert integer value to string (setq cnum (1+ --> 1 - plus value from cdr f = 3 (cdr f) --> 2 <-- last number used for "Big Beige Bay Window"
: "Big Beige Bay Window2" cdr being the rest of the list except the first one ("Big Beige Bay Window" . 2) 2 if we had used a non dotted pair like
("Big Beige Bay Window" 2) (cadr f) -> 2 | the second element of the list )))) (setq mlst (subst <-- more on this next time (cons <-- more on this next time (car f) <-- "Big Beige Bay Window" cnum <-- an integer assign from above statement ) f mlst )) Then update the value of mlist (("Big Beige Bay Window" . 2)) to
("Big Beige Bay Window" . 3) The statement below will evaluate if the above evaluates to nil (caddr id) --> #<VLA-OBJECT (strcat (cadr id) --> "Big Beige Bay Window" (itoa startnumber --> the value from the prompt "\nEnter Start Number: " say 2 )) ) Here we will build the list assigning the value to variable mlist (setq mlst (cons (cons (strcase (cadr id)) startnumber) mlst)) resulting in a dotted pair ("Big Beige Bay Window" . 2)

 

So you see, car/cadr/caddr/cdr are used for manipulating a list NOT a string value

 

So  (car "Big Beige Bay Window") will not give you "Big" nor (last "Big Beige Bay Window") "Window" because its a string and not a list.

 

Separating text string is a whole new ball game.

 

pBe

 

 

 

Message 22 of 26

Anonymous
Not applicable

Ahh, ok!  That actually makes so much more sense, thank you so very much for taking the time to explain it 🙂

 

It's not as easy to pick this up as I thought it was going to be!

 

Thanks,

cmaso

 

 

0 Likes
Message 23 of 26

Anonymous
Not applicable

Hello Pbejse
Just a thought, where did you learn lisp that well? Did you go on a course? I'm trying to pick it up but it's an uphill struggle.
- Simon

0 Likes
Message 24 of 26

hmsilva
Mentor
Mentor

@pbejse wrote:

 

First lets analyze the content of attval variable
    (("ID" "Big Beige Bay Window" #<VLA-OBJECT )("TAG2" "10x25x12" #<VLA-OBJECT ))
    
...

...

pBe


Nice explanation! Smiley Happy

 

Henrique

EESignature

0 Likes
Message 25 of 26

pbejse
Mentor
Mentor

hmsilva wrote:

Nice explanation! Smiley Happy


 

Thank you for that Henrique. I'm pretty sure you would've done the same, better even and thats why we're here 🙂 

 


sbanister wrote:

 

Hello Pbejse
Just a thought, where did you learn lisp that well? Did you go on a course? I'm trying to pick it up but it's an uphill struggle.
- Simon


I'm self taught Simon, found a Autodesk Customization book at the office one day and started reading and got hooked.

And of course, practice.. practice... practice

 

Thank you both.

 

pBe

0 Likes
Message 26 of 26

Anonymous
Not applicable

Sorry....!  I have yet more question 😞

 

In your fantastic explanation, you've highlighted that the variable f is a dotted pair list.  How did you set f as a dotted pair?  All I can find is information on cons creating the dotted list but cons isn't used until further down the lisp, and there it looks like it's used for the variable mlst.

 

With regards to the substitute line...

 

(setq mlst (subst (cons (car f) cnum) f mlst))
)

I know it goes substitute newitem olditem.  I'm just slightly lost with all of these parenthesis Smiley Embarassed  Is the "New item" (cons (car f) cnum) and the old item is (f mlst)?

 

I think I am well past owing you a pint now so I'll maybe hire a plane to spell "THANK YOU" in the sky.

 

Thanks,

cmaso 

0 Likes