Assist with stored variable numbers??

Assist with stored variable numbers??

DC-MWA
Collaborator Collaborator
764 Views
13 Replies
Message 1 of 14

Assist with stored variable numbers??

DC-MWA
Collaborator
Collaborator

Hello,

I know I'm going to get beat up for my crappy programming, but here goes.

I have a gas line sizing tool we use. I am trying to add a select points to gather lengths option in addition to the command line entry version that remembers the previous value.

I have it working as long as do not revert back to other method (Typeit ot Pickpoints). If I start with Typeit, it works great, go to Pickpoints, works great, go back to Typeit, fails or visa versa???

When I look at the results using (princ)

Typeit = 123

Pickpoints = 123.0

I've played with atoi, itoa... I do not know how to solve this although seems simple??

See lisp below.

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

(defun DO_GET_LEN (/ P1 P2)
(setq GET_LEN 0)
(while (setq P1 (getpoint "\nSelect first point, or press Enter to close: "))
(setq P2 (getpoint P1 "\nSelect second point: "))
(prompt
(strcat
"\nLatest distance = "
(rtos (distance P1 P2))
",\nCumulative distance = "
(rtos (setq GET_LEN (+ GET_LEN (distance P1 P2))))
); end strcat
); end prompt
); end while
(prompt (strcat "\nTotal sum of distances = " (rtos GET_LEN)))
(setq GET_LEN (/ GET_LEN 12))
;(setq GET_LEN (atoi (rtos (/ GET_LEN 12) 2 0)));test
;(setq GET_LEN (itoa (rtos (/ GET_LEN 12) 2 0)));test
(princ GET_LEN)
(princ)
); end defun

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

 

Thanks in advance for your assistance / input.

-DC

0 Likes
765 Views
13 Replies
Replies (13)
Message 2 of 14

Sea-Haven
Mentor
Mentor

Try something like this accepts point or distance.

 

(while (setq P1 (getpoint "\nSelect first point, or press Enter to close: "))
(setq dist  (getdist p1 "\nPick or enter distance "))
(princ dist)
)
0 Likes
Message 3 of 14

DC-MWA
Collaborator
Collaborator

I need to be able to ouch multiple points and add up the total distance.

0 Likes
Message 4 of 14

pbejse
Mentor
Mentor

@DC-MWA wrote:

I need to be able to ouch multiple points and add up the total distance.


That is going to be really painful.

Message 5 of 14

Kent1Cooper
Consultant
Consultant

@DC-MWA wrote:

I need to be able to ouch multiple points and add up the total distance.


Maybe one of the commands in SumDist.zip >here< will do what you want.  It sounds like probably SumDistCont.lsp with its SDC command would do.

Kent Cooper, AIA
0 Likes
Message 6 of 14

komondormrex
Mentor
Mentor

hey, for your attention

 

;*************************************************************************************************************************

;	komondormrex, mar 2023

;*************************************************************************************************************************

(defun c:do_get_length (/ crd before_last list_distance _result point_list result_string_list point
						  point_list result_string_list continue_execution
					   )

	;*********************************************************************************************************************

	(defun crd (_list)
		(reverse (cdr (reverse _list)))
	)

	;*********************************************************************************************************************

	(defun before_last (point_list)
		(nth (- (length point_list) 2) point_list)
	)

	;*********************************************************************************************************************

	(defun list_distance (point_list)
		(if (= 1 (length point_list))
			0.0
			(apply '+ (mapcar '(lambda (point_1 point_2) (distance point_1 point_2)) point_list (cdr point_list)))
		)
	)

	;*********************************************************************************************************************

	(defun _result (point_list)
		(if (= 1 (length point_list))
				"\rLatest distance: 0.0, Cumulative distance: 0.0"
				(strcat "\rLatest distance: "
						(rtos (distance (before_last point_list) (last point_list)))
						", Cumulative distance: "
						(rtos (list_distance point_list))
			    )
		)
	)

	;*********************************************************************************************************************

	(setq continue_execution t
		  point (getpoint "\nPick starting point: ")
		  point_list (append point_list (list point))
	)
	(setq result_string_list (append result_string_list (list (princ (_result point_list)))))
	(while (and
				continue_execution
				(not (null (setq point (vl-catch-all-apply 'getpoint (list (last point_list) "\nPick next point, <Esc> - one point backwards, RMB - cancel: ")))))
			)
				(cond
					(
						(null point)
							(redraw)
							(setq continue_execution nil)
					)
					(
						(vl-catch-all-error-p point)
							(if (< 1 (length point_list))
								(progn
									(grdraw (last point_list) (before_last point_list) -1 0)
									(setq point_list (crd point_list)
										  result_string_list (crd result_string_list)
									)
									(princ (strcat "\r" (last result_string_list)))
								)
								(progn
									(setq continue_execution nil)
									(redraw)
									(princ "\nEverything's undone")
								)
							)
					)
					(
						t
							(setq point_list (append point_list (list point)))
							(redraw)
							(mapcar '(lambda (point_1 point_2) (grdraw point_1 point_2 -1 0))
									 point_list (cdr point_list)
							)
							(setq result_string_list (append result_string_list (list (princ (_result point_list)))))
					)
				)
	)
	(princ)
)

;*************************************************************************************************************************
0 Likes
Message 7 of 14

ВeekeeCZ
Consultant
Consultant

Having a bit issue to understand you, so just making sure that you know what the built-in command has some to offer:

 

(command-s "_.dist" pause "_m")

0 Likes
Message 8 of 14

DC-MWA
Collaborator
Collaborator

Thanks Kent. The "Pickpoints" option was created using Sumdist.lsp.

It works great.

I don't think I am explaining the issue clearly. Both potions work independently.

I'm trying to have two options and be able work with them back and forth as develop the gas line size calcs.

DCMWA_0-1678812684547.png

If I use the "Pickpoints" and then run using "Typeit", I get this message

"bad argument type: fixnump: 97.8481"

I need these to work together.

I have assembled the parts in a little lisp so you can see how it is supposed to work.

Thank you for your time.

0 Likes
Message 9 of 14

DC-MWA
Collaborator
Collaborator

Thank you for your time. See reply to Kent below for further explanation of what I'm trying to achieve.

0 Likes
Message 10 of 14

DC-MWA
Collaborator
Collaborator

Ok all.

Thank all of you for your responses. I appreciate your time and expertise.

I solved the issue.

 

(defun DO_TYPEIT ()
(if (null GET_LEN)
(setq GET_LEN 100)
);end if
(initget 4)
(if (setq tmp (getdist (strcat "\nEnter Pipe Length <in decimal feet>: <" (rtos GET_LEN 2 2) ">: ")));getint
(setq GET_LEN tmp)
);if
(princ GET_LEN)
); end DO_TYPEIT defun

 

 

0 Likes
Message 11 of 14

ВeekeeCZ
Consultant
Consultant

Actually, the GETDIST is an elegant solution because it combines both methods into one.

 

(defun c:voodoo ( / a c)
  (setq a 0.)
  (while (setq c (getdist "\nDistance (pick or type-in): "))
    (princ (strcat "\n>> " (rtos c) " added to " (rtos (setq a (+ a c))))))
  (princ)
  )

 

0 Likes
Message 12 of 14

komondormrex
Mentor
Mentor

hey, there is no answer to Kent below)

what do you actually want? assuming you have drawn gas pipeline, you want to check some distances between some points on that line with cumulative distance altogether between 1st and last point?

0 Likes
Message 13 of 14

DC-MWA
Collaborator
Collaborator

This is very simple and seems to work. 

0 Likes
Message 14 of 14

DC-MWA
Collaborator
Collaborator

Actually this is part of larger program that develops gas line diagrams referencing the 2022 CA Plumbing Code.

0 Likes