List manipulation

List manipulation

avinash00002002
Collaborator Collaborator
3,346 Views
52 Replies
Message 1 of 53

List manipulation

avinash00002002
Collaborator
Collaborator

Hi!

I have a list which has nos. of vary members. 

(0.816176 6.48044 10.7246 10.3981 1.90985 8.48824 1.69765 3.39529 24.2404 1.63235 22.3306 1.50176 14.7075 17.4335 13.3526 13.3526 14.5769 5.8275 1.25691 11.8019 9.30441 7.72103 8.03118 4.35838 2.17103 3.65647)

I need help that
1. Which member have less than 4 than set to 4, and it will deduct from greater than 4.

Thanks,

Avinash

0 Likes
Accepted solutions (4)
3,347 Views
52 Replies
Replies (52)
Message 21 of 53

avinash00002002
Collaborator
Collaborator

Hi!

 

I have attached 20 samples for your reference. this has been created by existing .FAS file. it was came by automatically.

 

Thanks,

Avinash

0 Likes
Message 22 of 53

pbejse
Mentor
Mentor

@avinash00002002 wrote:

I have attached 20 samples for your reference. this has been created by existing .FAS file. it was came by automatically.


Good for you. Good to know you found a solution.

 

0 Likes
Message 23 of 53

avinash00002002
Collaborator
Collaborator

ThiS was .Fas file I don't have .LSP file,  I want to create new one with better coding. 

0 Likes
Message 24 of 53

pbejse
Mentor
Mentor

Note to self:

I think i know how its done. following the logic i posted earlier, it just needs an additional function than will round up/down the value to the nearest 0.5. as the total is always a whole number.

 

easy-peasy (lemon squeezy) 🙂

Good work pBe

patmyself.gif

0 Likes
Message 25 of 53

avinash00002002
Collaborator
Collaborator

Can you give me solutions for 230 mm fitting 

0 Likes
Message 26 of 53

pbejse
Mentor
Mentor

@avinash00002002 wrote:

Can you give me solutions for 230 mm fitting 


You have still NOT explain how it should work nor list the "rules" on how to deal with the values, Besides, as far as we can tell, the fas file works to your liking or as you have described it "came automatically" why re-invent the wheel by writing another code.

 


@avinash00002002 wrote:

  .. I want to create new one with better coding. 


It appears that only you understand what is working and what's not.

We  [ @marko_ribar @ronjonp  @hak_vz  and myself ] already outline our approach for you. You can build from that.

 

HTH

 

Like I said at post #16

-- Eventually someone will come along and help you---

---------------------------------------------------------------------------------------------------------------------------

(73 39 109 32 115 117 114 101 32 116 104 101 114 101 39 115 32 103 111 105 110 103 32 116 111 32 98 101 32 97 32 108 111 116 32 111 102 32 34 110 111 116 32 119 111 114 107 105 110 103 32 99 111 109 109 101 110 116 115 32 102 114 111 109 32 121 111 117 32 97 115 32 97 32 114 101 115 112 111 110 115 101)

 

0 Likes
Message 27 of 53

avinash00002002
Collaborator
Collaborator

Hi!

I have a another logic which you can do for me.

for about 6202 length

 

(25 35 35 35 35 35 282.5 33 48.5 36 80 23.5 5.5 74.5 19.5 92.5 825 105 16.5 679 442.5 43 57 20.5 39.5 247.5 237.5 40 597.5 70 10 38.5 731 462.5 10 367.5 66.5 35 35 35 35 35 25)

total length = 6202
Now,
230/6202 = 0.0370

now multiply 0.0370 to above dims.

(0.93 1.30 1.30 1.30 1.30 1.30 10.48 1.22 1.80 1.34 2.97 0.87 0.20 2.76 0.72 3.43 30.59 3.89 0.61 25.18 16.41 1.59 2.11 0.76 1.46 9.18 8.81 1.48 22.16 2.60 0.37 1.43 27.11 17.15 0.37 13.63 2.47 1.30 1.30 1.30 1.30 1.30 0.93)

now find how many numbers of value have less then 4.

Say, here 33 nos.

So, We have to accommodate 33 nos. of dims in 4mm. passage fitted.

33X4 = 132

Now summation of that dimensions (33nos.) which dimensions are less then 4 = 4872.5

now deduction

6202 - 1329.5 = 4872.5

now,

230-132 = 98

now,

98 / 4872.5 = 0.020113


now, remaining dimension multiply by 0.020113 then always coming more than 4.0.

 

Thanks,

Avinash

0 Likes
Message 28 of 53

hak_vz
Advisor
Advisor
Accepted solution

Try this

 

(defun plus_minus (lst fitting /  plusp set_nth i sum_list k co cu su so e m p)
	(defun plusp (num) (cond ((numberp num) (>= num 0.0))))
	(defun set_nth (lst n value)
	  (cond 
		((and (plusp n) (<= n (length lst)))
		  (cond
		   ((zerop n)
			 (cons value (cdr lst))
			)
			(t (cons (car lst) (set_nth  (cdr lst) (1- n) value)))
		  )
		)
	  )
	)
	(setq 
		i -1 
		sum_list (apply '+ lst)
		k (/ (float fitting) sum_list)
		cu 0
		co 0
		su 0
		so 0
	)
	(while (< (setq i (1+ i)) (length lst))
		(setq e (* k (nth i lst)))
		(if (< e 4.0) 
			(setq su (+ su e) cu (1+ cu))
			(setq so (+ so e) co (1+ co))
		)
		(setq lst (set_nth lst i e))
	)
	(setq m (- fitting (* cu 4.0)))
	(setq p (/ m (* (/ 1.0 k) so)))
	(setq i -1)
	(while (< (setq i (1+ i)) (length lst))
		(setq e (nth i lst))
		(if (<= e 4.0) 
			(setq lst (set_nth lst i 4.0))
			(setq lst (set_nth lst i (/ (* e p) k)))
		)
	)	
	lst
)

 

 

 

Command: (setq mmm '(0.816176 6.48044 10.7246 10.3981 1.90985 8.48824 1.69765 3.39529 24.2404 1.63235 22.3306 1.50176 14.7075 17.4335 13.3526 13.3526 14.5769 5.8275 1.25691 11.8019 9.30441 7.72103 8.03118 4.35838 2.17103 3.65647))
Command: (setq fff (plus_minus mmm 230))
(4 6.18917 10.2426 9.93075 4 8.10673 4 4 23.1509 4 21.3269 4 14.0465 16.6499 12.7525 12.7525 13.9217 5.56558 4 11.2715 8.88621 7.374 7.67021 4.16249 4 4)

 

for length 6177

 

Command: (setq mmm '(0.894873 1.25282 1.25282 1.25282 1.25282 1.25282 10.1121 1.18123 1.73605 1.28862 2.86359 0.84118 0.196872 2.66672 0.698001 3.31103 29.5308 3.75847 0.590616 24.3047 15.8392 1.53918 2.04031 0.733796 1.4139 8.85924 8.50129 1.4318 21.3875 2.50564 0.357949 1.3781 26.1661 16.5551 0.357949 13.1546 2.38036 1.25282 1.25282 1.25282 1.25282 1.25282))
Command: (setq fff (plus_minus mmm 230))
(4 4 4 4 4 4 5.91383 4 4 4 4 4 4 4 4 4 17.2704 4 4 14.214 9.26319 4 4 4 4 5.18112 4.97178 4 12.508 4 4 4 15.3026 9.68187 4 7.69316 4 4 4 4 4 4)

 

for length 3600

 

Command: (setq mmm '(25 35 35 35 35 35 35 35 130 141.5 69 49 640.5 652.5 247.5 900 50 50 33.5 61))
Command: (setq fff (plus_minus mmm 230))
(4 4 4 4 4 4 4 4 8.32512 9.06158 4.41872 4 41.0172 41.7857 15.8498 57.6355 4 4 4 3.9064)

 

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.
Message 29 of 53

avinash00002002
Collaborator
Collaborator

Thanks for your help , it works great.

Thank you so much

0 Likes
Message 30 of 53

pbejse
Mentor
Mentor
Accepted solution

@avinash00002002 wrote:

...
now, remaining dimension multiply by 0.020113 then always coming more than 4.0.

...


Not the way you think it works but if you have the correct algorithm as i described on post # 20 then it will work out fine.

 

 

0 Likes
Message 31 of 53

avinash00002002
Collaborator
Collaborator

Hi!

My list as below I want to summation of list is required rounded by 0.0.

 

Original value = 

50 50 161.29 357.71 900 112.67 787.33 583.06 316.94 799.67 100.33 900 116.28 683.72 50 50.5 = 6019.5

 

After 0.5 rounded

 

50 50 161.5 357.5 900 112.5 787.5 583 317 799.5 100.5 900 116.5 683.5 50 50.5 = 6019.5

 

I required that it takes some of adjustment and give 6019 or 6020 value.

 

may be if decimal value of up to 0.74 so function will rounding 0.5 but we need to change it 1.0

or

if decimal value of up to 0.24 so function will rounding 0.0 but we need to change it 0.5

 

like that

 

 

0 Likes
Message 32 of 53

hak_vz
Advisor
Advisor

@avinash00002002 

 

I'll take a look on it later today. One option is to simply add of subtract 0.5 from largest list entity. Or if you don't need to round values you can use this

(defun create_value_vector (n val / r ) (repeat n (setq r (cons val r))) r)
(setq a '(50 50 161.5 357.5 900 112.5 787.5 583 317 799.5 100.5 900 116.5 683.5 50 50.5))
(setq k (/ 6020.0 (apply '+ a)))
(setq m (create_value_vector (length a) k))
(setq b (mapcar '* a m))
(apply '+ b)

Modified list is stored in variable b

 

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 33 of 53

avinash00002002
Collaborator
Collaborator

I reqd. all rounded value 0.0 and 0.5.

 

 

0 Likes
Message 34 of 53

avinash00002002
Collaborator
Collaborator

My list is below

 

(setq a (list 50 50 161.29 357.71 900 112.67 787.33 583.06 316.94 799.67 100.33 900 116.28 683.72 50 50.5))

 Answer = 6019.51

 

I just rounded all elements by 0.5

(setq b (list 50 50 161.5 357.5 900 112.5 787.5 583 317 799.5 100.5 900 116.5 683.5 50 50.5))

answer = 6019.50

 

But I required B = 6019  or  6020 rounded

 

so, I have used 

(setq fixval (mapcar '(lambda (n)(- n (fix n))) a))

answer  = (0 0 0.29 0.71 0 0.67 0.33 0.06 0.94 0.67 0.33 0 0.28 0.72 0 0.5)

 

Now I want to two type of solution is

 

1. if fixval major/minor value = up to 0.22 then it will take 0.5 mm. at ones of any one of fixval so final fixval value is 6020

2. if fixval major/minor value = up to 0.74 then it will take next +1 value in at ones of any one of fixval so final fixval value is 6020

3. if fixval major/minor value = up to 0.23 to 0.74 then it will take +1 mm./or -0.5 at ones of any one of fixval so final fixval value is 6020

 

Thanks,

 

Avinash

 

0 Likes
Message 35 of 53

ronjonp
Mentor
Mentor

@avinash00002002 wrote:

My list is below

 

(setq a (list 50 50 161.29 357.71 900 112.67 787.33 583.06 316.94 799.67 100.33 900 116.28 683.72 50 50.5))

 Answer = 6019.51

 

I just rounded all elements by 0.5

(setq b (list 50 50 161.5 357.5 900 112.5 787.5 583 317 799.5 100.5 900 116.5 683.5 50 50.5))

answer = 6019.50

 

...

Thanks,

 

Avinash

 


Why are you rounding values within the list then summing them? You are introducing an error that will just get larger with longer lists.

0 Likes
Message 36 of 53

avinash00002002
Collaborator
Collaborator

Final length of any part of steel  must in rounding figures like 6020, 6019, 5235 etc...

 

0 Likes
Message 37 of 53

avinash00002002
Collaborator
Collaborator

Hi!

 

I want to know that if my rectangle is in rotated position then how to get x-dimensions.

Drawing is attached.

0 Likes
Message 38 of 53

ВeekeeCZ
Consultant
Consultant

Do it manually and give us the result in a format you're expecting to have.

Then we will see what you actually want. 

An additional question - how do you want to select it? Does the order matter?

0 Likes
Message 39 of 53

hak_vz
Advisor
Advisor

@ronjonp wrote:

@avinash00002002 wrote:

My list is below

 

(setq a (list 50 50 161.29 357.71 900 112.67 787.33 583.06 316.94 799.67 100.33 900 116.28 683.72 50 50.5))

 Answer = 6019.51

 

I just rounded all elements by 0.5

(setq b (list 50 50 161.5 357.5 900 112.5 787.5 583 317 799.5 100.5 900 116.5 683.5 50 50.5))

answer = 6019.50

 

...

Thanks,

 

Avinash

 


Why are you rounding values within the list then summing them? You are introducing an error that will just get larger with longer lists.


Why don't you just add 0.5 to largest entity or any other and sum is than 6020.  You can see on your screen how some combination works and where you can add delta value to round. Sorry but this is easy to do and not need any code.

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 40 of 53

hak_vz
Advisor
Advisor

@avinash00002002 wrote:

Hi!

 

I want to know that if my rectangle is in rotated position then how to get x-dimensions.


 

Returns distances (x) from rectangle bottom left corner. Pick two base points and select all inserts i.e. circle blocks.

(defun c:get_x_distances ( / p1 p2 p3 p4  ang1 ang2 ss i intpts distlist)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
(setq p1 (take 2(getpoint "\nRectangle bottom left point >")))
(setq p2 (take 2(getpoint "\nRectangle bottom rigth point >")))
(setq ang1 (angle p1 p2))
(setq ang2 (+ ang1 (* 0.5 PI)))
(princ "\nSelect all holes >")
(princ "\n>")
(setq ss (ssget '((0 . "INSERT"))))
(setq i -1)
(while (< (setq i (1+ i))(sslength ss))
(setq p3 (take 2(cdr (assoc 10 (entget(ssname ss i))))))
(setq p4 (take 2(polar p3 ang2 10)))
(setq intpts (cons (inters p1 p2 p3 p4 nil) intpts))
)
(setq intpts (vl-sort intpts (lambda (x y) (< (distance p1 x)(distance p1 y)))))
(setq i -1)
(while (< (setq i (1+ i)) (1-(length intpts)))
	(setq distlist (cons (rtos (distance (nth i intpts) p1) 2 2) distlist))
)
(mapcar 'atof(reverse distlist))
)

Applied to your sample

(25.0 60.0 95.0 130.0 165.0 200.0 295.0 379.94 430.0 1749.72 1755.21 3869.33 3904.33)

 

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