Call for help , cranking polyline

Call for help , cranking polyline

abdulellah.alattab
Advocate Advocate
7,342 Views
37 Replies
Message 1 of 38

Call for help , cranking polyline

abdulellah.alattab
Advocate
Advocate

Hello everyone, I need help drawing a bent-up or bent-down, cranking polyline.

 

The steps that the user performs are as follows: First, the user enters the distance L1 and then L2 either through the keyboard or by obtaining the distance by clicking on points P1 and P2 to obtain the distance L1 and by clicking on points P2 and P3 to obtain L2. Second, the user enters the parameters F1 and F2 through the keyboard only and the user enters the height H either through the keyboard or by choosing the distance between two points, whatever the user chooses. Third, the user enters the value of the angle through the keyboard, provided that the angle is between 0 and 90 degrees only. Fourth, the user chooses a point close to the end of the polyline at which the program will execute the task. If possible, the user chooses a point above or below the line to determine the side on which it will draw, either above or below the line. The program can execute the task on any polyline at any angle relative to the UCS.

 

It is preferable for the program to work on one side of the line, because the distances L1, L2 and the coefficients F1 and F2 often differ for each side of the line, and the task may be performed on one side or on both sides of the multi-line.

 

Thank you for all your efforts to make our work easier.

0 Likes
Accepted solutions (1)
7,343 Views
37 Replies
Replies (37)
Message 2 of 38

Kent1Cooper
Consultant
Consultant

[I believe the diagonal distance is h divided [not multiplied] by the sine of the angle.  The sine will always be no greater than 1, so multiplying h by it will result in a smaller number, not the larger number of the intended diagonal distance.]

Kent Cooper, AIA
Message 3 of 38

abdulellah.alattab
Advocate
Advocate

You correct , A mistake I made, work pressure causes mental distraction .

Message 4 of 38

Sea-Haven
Mentor
Mentor

This is the front end for you. Save Multi getvals.lsp to a support path or edit the Load path.

SeaHaven_0-1741650946754.png

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/call-for-help-cranking-polyline/td-p/13362612
; Cranked reobar By AlanH March 2025

(defun c:reobar ( / oldsnap ans l1 l2 f1 f2 l3 l4 pt1 pt2 pt3 pt4 dist)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "L1" 5 4 "1000" "L2" 5 4 "1000" "F1" 5 4 "20" "F2" 5 4 "20" "Height" 5 4 "20" "Angle"  5 4 "30")))
(setq l1 (atof (nth 0 ans))
l2 (atof (nth 1 ans))
f1 (atof (nth 2 ans))
f2 (atof (nth 3 ans))
ht (atof (nth 4 ans))
ang (* pi (/ (atof (nth 5 ans)) 180.0)) 
)
(setq l3 (/ l1 f1))
(setq l4 (/ l2 f2))
(setq pt1 (getpoint "\nPick a point "))
(setq pt2 (polar pt1 0.0 (- l1 l3)))
(setq h (/ ht (sin ang)))
(setq pt3 (polar pt2 ang h))
(setq dist (+ l4 (- l3 (* (cos ang) ht))))
(setq pt4 (polar pt3 0.0 dist))
(command "pline" pt1 pt2 pt3 pt4 "")
(setvar 'osmode oldsnap)
(princ)
)
(c:reobar)

 

 

I can add the direction change up/down or right/left.

 

 

0 Likes
Message 5 of 38

abdulellah.alattab
Advocate
Advocate

Thank you for your effort, but I want to choose an already drawn polyline and not draw a new line.

0 Likes
Message 6 of 38

abdulellah.alattab
Advocate
Advocate

Can the crank2 command in this lib be modified to do this task?

0 Likes
Message 7 of 38

abdulellah.alattab
Advocate
Advocate

I promise you this is my last request in this forum, I hope you can help me

0 Likes
Message 8 of 38

komondormrex
Mentor
Mentor

@abdulellah.alattab wrote:

this is my last request in this forum


why is that?

 

komondormrex_0-1741716867145.png

is there a vertex on a pline before?

0 Likes
Message 9 of 38

abdulellah.alattab
Advocate
Advocate

Mouse click close to the end of the polyline where you want to create a crank, not a vertex.

0 Likes
Message 10 of 38

abdulellah.alattab
Advocate
Advocate

Mouse click close  or near to the end of the polyline where you want to create a crank,  " p4 "it is not a polyline vertex.

0 Likes
Message 11 of 38

Sea-Haven
Mentor
Mentor

Ok if you want pick p1 p2 p3 the distance between can be displayed in the dcl, so change or keep. 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/call-for-help-cranking-polyline/td-p/13362612
; Cranked reobar By AlanH March 2025

(defun c:reobar ( / oldsnap ans l1 l2 f1 f2 l3 l4 pt1 pt2 pt3 pt4)
(setq oldsnap (getvar 'osmode))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq pt1 (getpoint "\nPick 1st point")
  pt2 (getpoint pt1 "\nPick 2nd point")
  pt3 (getpoint pt2 "\nPick 3rd point"))
(setq d1 (distance pt1 pt2))
(setq d2 (distance pt2 pt3))

(setvar 'osmode 0)

(setq ans (AH:getvalsm (list "Enter values " "L1" 8 7(rtos d1 2 2)  "L2" 8 7 (rtos d2 2 2) "F1" 5 4 "20" "F2" 5 4 "20" "Height" 5 4 "20" "Angle"  5 4 "30")))

(setq l1 (atof (nth 0 ans))
  l2 (atof (nth 1 ans))
  f1 (atof (nth 2 ans))
  f2 (atof (nth 3 ans))
  ht (atof (nth 4 ans))
  ang (* pi (/ (atof (nth 5 ans)) 180.0)) 
  l3 (/ l1 f1)
  l4 (/ l2 f2)
)
(setq pt2 (polar pt1 0.0 (- l1 l3)))
(setq h (/ ht (sin ang)))
(setq pt3 (polar pt2 ang h))
(setq dist (+ l4 (- l3 (* (cos ang) ht))))
(setq pt4 (polar pt3 0.0 dist))
(command "pline" pt1 pt2 pt3 pt4 "")

(setvar 'osmode oldsnap)
(princ)
)
(c:reobar)

 

 

If happy will add the delete original line and add the up/down option.

Message 12 of 38

abdulellah.alattab
Advocate
Advocate

Thank you, there is an error in calculating the length L4 , F1 = 4 , F2= 3, but the original polyline is still there. You may wonder why the best way to select the original polyline is to click on a point near one of its ends. The reason is that the user wants to add a crank again on the other end of the polyline. I have attached a lisp file containing a command called crank2. If it is possible to develop it to shrink the original polyline by L3 and add the length L4, and of course, as I mentioned, the way to define distances is by clicking on the points.

0 Likes
Message 13 of 38

abdulellah.alattab
Advocate
Advocate

Without dcl window wil better 

0 Likes
Message 14 of 38

Sea-Haven
Mentor
Mentor

When you ask for some help its a good idea to lay out all options, as your now asking for 2 cranks, I based my code on drawing what you provided rather than picking an end and apply rules, Yes original line is still there I on purpose did not erase till you were happy.

 

I will have a think some more. 

Message 15 of 38

abdulellah.alattab
Advocate
Advocate

I am sorry mr @Sea-Haven , i now that ,  can you try this lisp with cranck2 command 

, some thing like it 

0 Likes
Message 16 of 38

komondormrex
Mentor
Mentor
Accepted solution

@abdulellah.alattab 

check the following code

 

(defun c:crank_pline (/ pt1 point_1 pt2 point_2 pt3 point_3 pt4_point_4 max_f1 max_f2angle_plus f1 f2 pt2_1 ang_point angle_ height pline_to_crank pt4_1)
  	(setvar 'pdmode 34)
  	(setq pt1 (getpoint "\nPick Point 1: ")
  		  point_1 (entmakex (list '(0 . "point") (cons 10 pt1)))
  		  pt2 (getpoint pt1 "\nPick Point 2: ")
  		  pt2 (list (car pt2) (cadr pt1))
  		  point_2 (entmakex (list '(0 . "point") (cons 10 pt2)))
		  pt3 (getpoint pt2 "\nPick Point 3: ")
		  pt3 (list (car pt3) (cadr pt1))
  		  point_3 (entmakex (list '(0 . "point") (cons 10 pt3)))
		  pt4 (getpoint pt3 "\nPick Point 4: ")
		  pt4 (list (car pt4) (cadr pt1))
  		  point_4 (entmakex (list '(0 . "point") (cons 10 pt4)))
  		  max_f1 (abs (car (mapcar '- pt2 pt1)))
  		  max_f2 (abs (car (mapcar '- pt3 pt2)))
		  angle_plus (if (> (car pt1) (car pt2)) '- '+)
	)
  	(while (> (setq f1 (getreal (strcat "\nEnter coefficient F1 (max " (rtos max_f1 2 2) "): "))) max_f1))
  	(while (> (setq f2 (getreal (strcat "\nEnter coefficient F2 (max " (rtos max_f2 2 2) "): "))) max_f2))
	(setq pt2_1 (polar pt2 (angle pt2 pt1) (/ (distance pt1 pt2) f1))
		  height (getdist pt2_1 "\nEnter height: ")
	)
	(while (and (setq ang_point (getpoint pt2_1 "\nPick angle point: "))
				(equal (car ang_point) (car pt2_1))
				(equal (cadr ang_point) (cadr pt2_1))
		   )
	)
	(setq angle_ (atan (abs (apply '/ (reverse (mapcar '- ang_point pt2_1 '(0 0))))))
		  pline_to_crank (car (entsel "\nPick pline to crank: "))
	)
	(vla-put-coordinates (vlax-ename->vla-object pline_to_crank)
			 			 (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 7)) 
						 					  (apply 'append (mapcar '(lambda (point) (mapcar '+ '(0 0) point)) 
											  						  (list pt1 pt2_1 (setq pt4_1 (polar pt2_1 ((eval angle_plus) (angle pt1 pt2) angle_) (/ height (sin angle_))))
																					  (list (car (polar pt2 (angle pt1 pt2) (/ (distance pt2 pt3) f2))) (cadr pt4_1))
																	  )
															 )
											  )
						 )
	)
	(mapcar 'entdel (list point_1 point_2 point_3 point_4))
	(princ)
)

 

0 Likes
Message 17 of 38

abdulellah.alattab
Advocate
Advocate

Thank you ,

Please , Can you send code as lisp format file 

0 Likes
Message 18 of 38

abdulellah.alattab
Advocate
Advocate

Forget it, I used my computer browser and copied it to Visual Lisp editor, I'm trying it now

0 Likes
Message 19 of 38

komondormrex
Mentor
Mentor

lisp file attached

 

0 Likes
Message 20 of 38

abdulellah.alattab
Advocate
Advocate

There are restrictions on the values ​​of F1 and F2 , 

Is it possible not to associate the values ​​of F1 and F2 with the length of the line? They are division coefficients and not lengths.

0 Likes