Jump to content

Recommended Posts

Posted (edited)

What better way to store points in a vector and

then grab a determinda position:

 

ADD VALUES:

maxvector[].add(2761.11 1898.11 0.0)

maxvector[].add (3761.12 1538.43 0.0)

maxvector[].add(4761.15 2598.58 0.0)

 

RESULT:

maxvector[]

0 = (2761.11 1898.11 0.0)

1 = (3761.12 1538.43 0.0)

2 = (4761.15 2598.58 0.0)

 

And then a way to get this value at a given position

Ex:

(print maxvector[1])

RESULT:

(3761.12 1538.43 0.0)

Edited by rodrigo_sjc_sp
Posted

Use a list:

(setq maxvector
  '(
       (2761.11 1898.11 0.0)
       (3761.12 1538.43 0.0)
       (4761.15 2598.58 0.0)
   )
)

Then:

(nth 1 maxvector)

Posted

Lee ,

 

Using your sample

(setq maxvector
  '(
       (2761.11 1898.11 0.0)
       (3761.12 1538.43 0.0)
       (4761.15 2598.58 0.0)
   )
)

How to add a new value(point) in maxvector via lisp ?

Posted

(setq maxvector (cons '(3411.11 9418.11 0.0) maxvector))

 

PS: Please edit your post and enclose your code with code tags:

 

[highlight][noparse]

[/noparse][/highlight] Your code here [highlight][noparse]

[/noparse][/highlight]

Posted

:)Thank you, now fix the tags

Posted

Lee, how can I get the value using a variable?

 

(setq counting 1)
(nth counting maxvector)

Posted

ok lee, is that I am using this code and it is returning a wrong position,

should be something of the logic then.

 

 

 

 

thank you:ouch:

Posted

Remember that the indices for the nth function are zero-based (i.e. the first item is at index 0), and that the cons function will add a new item to the start of the list.

Posted

How do I remove an item from the vector? example.....remove item 3 of vector

ex:

(maxvector remove 3)

Posted

Consider a 'Remove Nth' function:

;; Remove Nth  -  Lee Mac
;; Removes the item at the nth index in a supplied list

(defun LM:RemoveNth ( n l )
   (if (and l (< 0 n))
       (cons (car l) (LM:RemoveNth (1- n) (cdr l)))
       (cdr l)
   )
)

Or iteratively:

;; Remove Nth  -  Lee Mac
;; Removes the item at the nth index in a supplied list

(defun LM:RemoveNth ( n l / i )
   (setq i -1)
   (vl-remove-if '(lambda ( x ) (= (setq i (1+ i)) n)) l)
)

(LM:RemoveNth 3 maxvector)

Posted

Thanks lee

 

I made a change in my code using the CDR function

 

     (setq maxvector (cdr maxvector))       

 

The result excludes the first item, it was what I needed

Thanks

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