amend my script

amend my script

Anonymous
Not applicable
831 Views
12 Replies
Message 1 of 13

amend my script

Anonymous
Not applicable

(if (and a b)
(progn
(if (assoc a lst)
(setq lst (subst (cons a (+ b (cdr (assoc a lst)))) (assoc a lst) lst))
(setq lst (cons (cons a b) lst))
);; if
(setq a nil b nil)
);; progn
);; if


When I use the above code in my script I am getting the values in the below format


(("PART01" . 6.0)("PART02" . 4.0)("PART03" . 3.5))


But I am looking for a way to add quotations to all second items aswell inside the list like below:


(("PART01" . "6.0")("PART02" . "4.0")("PART03" . "3.5"))

0 Likes
832 Views
12 Replies
Replies (12)
Message 2 of 13

hak_vz
Advisor
Advisor

Convert second part to string using function RTOS

(rtos (+ b (cdr (assoc a lst))) 2 1)
and
(rtos b 2 1)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 13

Anonymous
Not applicable

(if (and a b)
(progn
(if (assoc a lst)
(setq lst (subst (cons a (rtos (+ b (cdr (assoc a lst)))2 1)) (assoc a lst) lst))
(setq lst (cons (cons a (rtos b 2 1)) lst))
)
(setq a nil b nil)
)
)

 

*****************

Thank you for your reply Hak. I am unsure where to copy your code. When I tried amending your code like above format it gives me an error. Please help me if I copied incorrectly in the code

0 Likes
Message 4 of 13

hak_vz
Advisor
Advisor

Update your script and sample data. It is hard to work on a part of the script without sample data to test.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 13

Anonymous
Not applicable

(progn

(setq s1 (ssget "_x"(list '(0 . "INSERT")'(2 . "SOR_1,`**")'(66 . 1)(cons 410 (getvar 'CTAB)))))

(repeat
(setq i (sslength s1))
(setq hnd (ssname s1 (setq i (1- i))))
(setq ent (entget hnd))
(setq attlst nil)
(setq obj (vlax-ename->vla-object hnd))
(setq attlst (vlax-invoke obj 'GetAttributes));; setq

(foreach att attlst
(cond ((and (= (strcase (vla-get-TagString att)) "PART_1")
(/= (vla-get-TextString att) ""))
(setq a (vla-get-TextString att))
)
((and (= (strcase (vla-get-TagString att)) "Quantity")
(/= (vla-get-TextString att) ""))
(setq b (atof (vla-get-TextString att)))
)
);; cond
);; foreach


(if (and a b)
(progn
(if (assoc a lst)
(setq lst (subst (cons a (rtos (+ b (cdr (assoc a lst)))2 1)) (assoc a lst) lst))
(setq lst (cons (cons a (rtos b 2 1)) lst))
);; if
(setq a nil b nil)
);; progn
);; if

);; repeat


(if lst
(progn
(setq lst (vl-sort lst (function (lambda (a b) (< (car a) (car b))))))
(setq i 0)


(setq tmp_lst (reverse lst))

(setq sel_lst (cons '("PART NAME." "Quantity") sel_lst))
(setq sel_lst (append sel_lst lst))
(gc:WriteExcel file nil nil sel_lst)

); progn

 

*************************

 

Here is the part of my code. I am just trying to export the sum of attribute values into existing excel. I tried in so many ways but I am unable to do it. I am just a basic scripter in lisp. If possible can you have a quick look in my code and what's wrong to populate the list in excel. With my code I can extract the values of Part name but not the sum of quantity in my excel. Thanks in advance

0 Likes
Message 6 of 13

hak_vz
Advisor
Advisor

I am just a basic scripter in lisp.


Script is written OK,  at least this part. You have

 

(setq a (vla-get-TextString att))  -> string

(setq b (atof (vla-get-TextString att))) -> real  to enable later calculation

 

(if (and a b)
(progn (if (assoc a lst)  -> what is in lst ?

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 13

Anonymous
Not applicable

(if (and a b)
(progn (if (assoc a lst)  -> what is in lst ?

 

List of attribute values from each entities. I copy this part from another program which gives me to calculate the sum of attribute values based on the attribute tag for each part names .

0 Likes
Message 8 of 13

hak_vz
Advisor
Advisor
(+ b (cdr (assoc a lst)))

here is error

You have b converted to real but a is a text

it should be

(+ b (atof(cdr (assoc a lst))))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 13

Anonymous
Not applicable

No luck Hak.. I tried to replace my code with "(+ b (atof(cdr (assoc a lst)))" but still not working

0 Likes
Message 10 of 13

hak_vz
Advisor
Advisor

Sorry, will try to look on later.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 11 of 13

Anonymous
Not applicable

Okay sure, thank you

0 Likes
Message 12 of 13

Sea-Haven
Mentor
Mentor

Posted at cadtutor as well.

0 Likes
Message 13 of 13

Anonymous
Not applicable

Hi yes, I posted this query in other forum aswell. Iam awaiting for the correct code for my script. I have searched so many forums for this type script and unable to find the correct code. So I have posted in forums, someone can help me to resolve my coding issue. 

0 Likes