Increase The Y Coordinate

Increase The Y Coordinate

thabit79BL3
Enthusiast Enthusiast
537 Views
7 Replies
Message 1 of 8

Increase The Y Coordinate

thabit79BL3
Enthusiast
Enthusiast

Hello, 

 

I defined a starting point (as a List) and inside the WHILE loop, I'm trying to increase the Y coordinate by a fixed jump of 45, but I was not able to realize it. 

 

(setq pt1 '(0 0 0))
(setq count 0)
(while (< count 2)
(command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" pt1 "1" "1" "0")
  (subst '45 '0 pt1)
  (setq (cadr pt1) 45)
  (setq count (1+ count))
)
 
Thanks 🙂




0 Likes
Accepted solutions (3)
538 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor
Accepted solution

@thabit79BL3 wrote:

Hello, 

 

I defined a starting point (as a List) and inside the WHILE loop, I'm trying to increase the Y coordinate by a fixed jump of 45, but I was not able to realize it. 

 

(setq pt1 '(0 0 0))
(setq count 0)
(while (< count 2)
(command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" pt1 "1" "1" "0")
  (subst '45 '0 pt1)
  (setq (cadr pt1) 45)
  (setq count (1+ count))
)

Couple of things 

(setq count 0)(< count 2)

That will always be the same number of loop  as you are setting count as 0, might as well use

(repeat 2

 

Using the function subst will replace all instance of the item on the target list.

(subst '45 '0 pt1) --- > (45 45 45)

The result will be NOT just a Y ( 2nd item ) substitution but all matching value

 

(setq (cadr pt1) 45) ==> bad variable name in SETQ: (CADR PT1)

There are rules for variable naming, here is a good topic to read -- > AutoLISP Lesson 5 – VARIABLES 

 

Suggested modification

(setq pt1 '(0 0 0))
(repeat 2
(command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" pt1 "1" "1" "0")
(setq TheYValue (cadr pt1))
(setq pt1 (list (car pt1) (+ '45 TheYValue) (last pt1) ))
	)

 

HTH

0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

A couple of other ways to do that [you can read about the functions involved in the AutoLisp Reference]:

....

(command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" pt1 "1" "1" "0")
  (setq pt1 (polar pt1 (/ pi 2) 45))
  (setq count (1+ count))
....
or:

....

(command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" pt1 "1" "1" "0")
  (setq pt1 (mapcar '+ pt1 '(0 45 0)))
  (setq count (1+ count))
....
 
Kent Cooper, AIA
0 Likes
Message 4 of 8

thabit79BL3
Enthusiast
Enthusiast

Regards @pbejse , @Kent1Cooper 
Thank you very much for your cooperation.

I am new to LISP commands and haven't been able to find any good tutorials yet 😅

so I have another question, in my code I will also have to add the name of the circuit (for example FC1, FC2, FC3,...) so how can this be done inside the WHILE loop.
The updated code:

 

(defun C:foo ()
  (setq TagName "FC1")
  (setq count 0)
  (setq point '(45 248))
  (while (< count (atof eb17))
    (command "-insert" "lib\\Libs\\iec-60617\\VCB1_FC1P" point "1" "1" "0"   TagName  "" "" """)
    (setq count (1+ count))
    (setq TheYValue (car point))
    (setq point (list (+ '35 TheYValue) (cadr point) ))
 
  )
 
)
 
Thanks

 

 

0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

[It seems very odd to me to have a variable called TheYValue that contains the X coordinate of a point list.  Also, the triple double-quote character at the end of the Insert command can't be right.]

 

I would say, instead of setting TagName to "FC1" at the beginning, if it's supposed to start at FC1 and increment upward, set a different variable name such as TagNumber to 0, and increment it upward within the Insert command, like this:

... "1" "1" "0" (strcat "FC" (itoa (setq TagNumber (1+ TagNumber)))) "" "" "")

 

Kent Cooper, AIA
0 Likes
Message 6 of 8

thabit79BL3
Enthusiast
Enthusiast

Hi @Kent1Cooper 

Actually I'm still trying to implement functions, there may be many mistakes in the names of the functions or variables and that's because I'm still trying the implementations to understand the language before I start programming.


I had a very similar idea to the one you gave, but unfortunately it doesn't work well for my code and that's because I'm using DCL for the input.

The idea is that I receive data from the user (in each DCL page there are almost 10 lines) and I want to go through all the data I receive from the user, which means that I need to go through all the user's input in my WHILE, so I need an operation (if there is one) that replaces (or adds 1) in evry STRING last char.


I really appreciate your help thanks ❤️

 

 

 

 
0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@thabit79BL3 wrote:

... I need an operation (if there is one) that replaces (or adds 1) in evry STRING last char.

....


If STRING is a variable that contains something like "FC1" from the User, but the "root" of that might not always be "FC", and assuming the "last char." may be [or may become] more than one character [once it gets up to 10 and beyond], but always represents an integer that can be incremented, try an approach like this [I leave it to you to incorporate into your other code]:

 

Command: (setq string "FC1"); assuming it comes from the User this way
"FC1"
Command: (setq root (vl-string-right-trim "0123456789" string)); lop off numerical end

"FC"
Command: (setq inc (atoi (substr string (1+ (strlen root))))); numerical end converted to number
1
Command: (setq newTag (strcat root (itoa (setq inc (1+ inc))))); increment and add as suffix to root
"FC2"
Command: (setq newTag (strcat root (itoa (setq inc (1+ inc))))); and again, etc.
"FC3"

 

Another example with different starting conditions:

 

Command: (setq string "ABC123")
"ABC123"
Command: (setq root (vl-string-right-trim "0123456789" string))
"ABC"
Command: (setq inc (atoi (substr string (1+ (strlen root)))))
123
Command: (setq newTag (strcat root (itoa (setq inc (1+ inc)))))
"ABC124"
Command: (setq newTag (strcat root (itoa (setq inc (1+ inc)))))
"ABC125"

Kent Cooper, AIA
0 Likes
Message 8 of 8

thabit79BL3
Enthusiast
Enthusiast

@Kent1Cooper  Thank you very much you're a life saveor! 

0 Likes