Jump to content

Recommended Posts

Posted

Hi,

 

I have a little project where I want to create a command that automatically determine distance betw. two points on a line, then take the results and divide it by 350. If the result is say 4.3 or 4.5, I round it to a higher figure i.e 5 (2.3 >> 4, 3.2 >> 4 etc.,) and divide the line with that round figure. Finally I have to place horizontal line say 300mm. long midpoint along those points.

 

For the distance, I gleaned from this very forum the following:

 

(setq pt1 (getpoint "\nPick First Point"))

(setq pt2 (getpoint "\nPick Second Point"))

(setq dist (distance pt1 pt2))

 

The above seemed evident and correct. Then how to use and apply the dist value I got from the program above.

 

Thank you very much.

 

Nicolas.

Posted

Hello

 

You can try this I just have made for you.

(defun c:try (/ pt1 pt2 dist absLen Lens Line)
 (setq pt1 (getpoint "\nPick First Point")
       pt2 (getpoint "\nPick Second Point")
       dist (distance pt1 pt2)
absLen (abs dist)
)
 (setq Lens(getint "\nEnter Number to divide on :")
	)  
 (setvar 'pdmode 66)
 (vl-cmdf "_.line" pt1 pt2 "")
 (setq Line (entlast))
 (vl-cmdf "_.divide" Line Lens
   "_.erase" Line "") 
(princ)
)

 

Regards

 

Tharwat

Posted

Thank you very much. The program does divide the line by the number I entered. However, the plan is a bit different.

 

I want to have the distance (absolute value) and divide it by 350. The number should be round up (i.e if the answer is 2, then its ok but if it is 2.1 then it should be rounded to 3 or 2.5 to 3 or 2.6 to 3 and etc.).

 

With this number, I can then divide the original line by it and then place a hoizontal line of 300mm. along the dot (pdmode 66)

 

Hope to hear from you,

 

Nicolas.

Posted

to round up

(if (not
 (zerop (rem dist 1.0)))
 (setq dist (1+ (fix dist))))

Posted

Hi

 

Some modifications But your selection must start from Left to Right.

(defun c:try (/ pt1 pt2 dist absLen Lens Line)
 (setq pt1 (getpoint "\nPick First Point")
       pt2 (getpoint "\nPick Second Point")
       dist (distance pt1 pt2)
fixDist (fix dist)
fixPT2 (list (+ (car pt1) fixDist)
	     (cadr pt1))
)
 (setq Lens(getint "\nEnter Number to divide on :")
	)  
 (setvar 'pdmode 66)
 (vl-cmdf "_.line" pt1 fixPT2 "")
 (setq Line (entlast))
 (vl-cmdf "_.divide" Line Lens
   "_.erase" Line "") 
(princ)
)

 

Regards

 

Tharwat

Posted
to round up

(if (not
 (zerop (rem dist 1.0)))
 (setq dist (1+ (fix dist))))

 

(fix (+ 0.5 x))

 

To account for negatives:

 

(fix (+ x (/ (abs x) x 2.)))

Posted
(fix (+ 0.5 x))

To account for negatives:

 

(fix (+ x (/ (abs x) x 2.)))

 

(float (fix (+ 0.5 x)))

Posted

I think the OP wanted any decimal greater than 0 rounded up to an integer. Abs not necessary since variable obtained from Distance function.

Posted
I think the OP wanted any decimal greater than 0 rounded up to an integer. Abs not necessary since variable obtained from Distance function.

 

True, twas just for completeness :)

Posted

Here it goes once again but in another technique and absolute value ....

(defun c:try (/ pt1 pt2 dist absLen Lens Line)
 (setq pt1 (getpoint "\nPick First Point")
       pt2 (getpoint "\nPick Second Point")
       dist (distance pt1 pt2)
   fixDist (float (fix (+ 0.5 dist)))
   fixPT2 (list (+ (car pt1) fixDist)
            (cadr pt1))
   )
  (setq Lens(getint "\nEnter Number to divide on :")
       )  
 (setvar 'pdmode 66)
 (vl-cmdf "_.line" pt1 fixPT2 "")
 (setq Line (entlast))
 (vl-cmdf "_.divide" Line Lens
      "_.erase" Line "") 
(princ)
)

I hope this fit your needs .....

 

Regards

 

Tharwat

Posted

Hi,

 

Many Thanks to all of you for all the details. I am checking them right away.

 

Nic.

Posted

Hi,

 

I have copy and run the lisp program but it is not working on the horizontal plane. Also it continues to look for the number to divide. Actually I want the program to automatically derive this with a built-in formula namely take the distance and divide it by 350 and round up the number in case it yield decimal. There is no room for decimal. I am looking for an equivalent of the ceiling command in Excel. However, there is also no room for any decimal value at all. If the result is 5.1, it should be round up to the next integer namely 6. If the result if 5, then it's ok.

 

I have included a more graphic description of what I am looking for. I believe that the information will help me one way or another. However, this is but the first step of an overall project that automatically set dowels along horizontal and vertical planets with much more complex conditions.

 

Sincerely Yours,

 

Nic.

Dowel to Windows Research.dwg

Posted

Actually the problem is that you can not consider the decimal number while you are using lengths in mm. So the decimal that you want would be here multipied 3 times and the formula would be as following;

0.5 =50

1.0 =100 and so on which means that decimal almost in this case nothing.

 

Regards

Tharwat

Posted

Hi,

 

I was thinking about this little project this morning and came upon a possible solution. I can use REMAINDER. For example, if the number is divisible by 350, there will be no remainder (remainder =0) and the number is automatically used to divide the distance. However if the remainder is anything except 0, the number should be incremended by 1. In this case, there is an IF...ELSE condition that need to be implemented in the program. Can anybody please help me with this?

 

Regards,

Nicolas.

Posted
Hi,

 

I was thinking about this little project this morning and came upon a possible solution. I can use REMAINDER. For example, if the number is divisible by 350, there will be no remainder (remainder =0) and the number is automatically used to divide the distance. However if the remainder is anything except 0, the number should be incremended by 1. In this case, there is an IF...ELSE condition that need to be implemented in the program. Can anybody please help me with this?

 

Regards,

Nicolas.

Look at post #4

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