Jump to content

make & call subfunction with parameter / shorten line at start and end


Recommended Posts

Posted

hi all.

 

i wonder if anybody can tell me how I can put the following code into a sub-function, so that i can call it several times in the main function.

 

the idea is to pass a polyline / entity together with one parameter that defines the trimming length on both ends of the polyline. it should return the trimmed polyline.

 

here's the code i have:

 

; active object
(setq myline (entlast))
 
; trip distance
(setq trim_dist 50)

; First Break Point Sets
(setq start_point (vlax-curve-getPointAtDist myobj 0))
(setq trim_point (vlax-curve-getPointAtDist myobj trim_dist))

; First Break
(command "._break" myline "_non" (trans start_point 0 1) "_non" (trans trim_point 0 1))

(setq myline (entlast))

; Second Break Point Sets
(setq edpt (vlax-curve-getendparam myline))
(setq el_length (vlax-curve-getDistAtParam myline edpt)) ; length of element
(setq trim_point2 (vlax-curve-getPointAtDist myline (- el_length trim_dist)))
(setq end_point (vlax-curve-getPointAtDist myline el_length))

; Second Break
(command "._break" myline "_non" (trans end_point 0 1) "_non" (trans trim_point2 0 1))

; Result
(setq result_line (entlast))

Posted

I believe this is what you were looking for:

[color=magenta](defun TrimPline( myline trim_dist[/color]
[color=magenta]                / start_point trim_point edpt el_length trim_point2 end_point )[/color]
; First Break Point Sets
(setq start_point (vlax-curve-getPointAtDist [color=red]myline[/color] 0))
(setq trim_point (vlax-curve-getPointAtDist [color=red]myline[/color] trim_dist))

; First Break
(command "._break" myline "_non" (trans start_point 0 1) "_non" (trans trim_point 0 1))

; Second Break Point Sets
(setq edpt (vlax-curve-getendparam myline))
(setq el_length (vlax-curve-getDistAtParam myline edpt)) ; length of element
(setq trim_point2 (vlax-curve-getPointAtDist myline (- el_length trim_dist)))
(setq end_point (vlax-curve-getPointAtDist myline el_length))

; Second Break
(command "._break" myline "_non" (trans end_point 0 1) "_non" (trans trim_point2 0 1))

; Result
[color=red] myline[/color]
[color=magenta])[/color]

[color=magenta](while (setq ssetPline (ssget "_:S" '((0 . "LWPOLYLINE"))))[/color]
[color=magenta] (TrimPline (ssname ssetPline 0) 50.0)[/color]
[color=magenta])[/color]

Please note that I have made some other correction to your code; you need also to add some validations to don't exceed polyline's length with the trim size.

Posted

thanks Mircea,

I think this goes into the right direction.

 

allow me to be more concrete, in my main script, i will create a polyline (boundary) and explode it. I want to pass the exploded segments of this boundary to this subfunction to shorten all of them.

 

martin

 

 

I believe this is what you were looking for:

[color=magenta](defun TrimPline( myline trim_dist[/color]
[color=magenta]                / start_point trim_point edpt el_length trim_point2 end_point )[/color]
; First Break Point Sets
(setq start_point (vlax-curve-getPointAtDist [color=red]myline[/color] 0))
(setq trim_point (vlax-curve-getPointAtDist [color=red]myline[/color] trim_dist))

; First Break
(command "._break" myline "_non" (trans start_point 0 1) "_non" (trans trim_point 0 1))

; Second Break Point Sets
(setq edpt (vlax-curve-getendparam myline))
(setq el_length (vlax-curve-getDistAtParam myline edpt)) ; length of element
(setq trim_point2 (vlax-curve-getPointAtDist myline (- el_length trim_dist)))
(setq end_point (vlax-curve-getPointAtDist myline el_length))

; Second Break
(command "._break" myline "_non" (trans end_point 0 1) "_non" (trans trim_point2 0 1))

; Result
[color=red] myline[/color]
[color=magenta])[/color]

[color=magenta](while (setq ssetPline (ssget "_:S" '((0 . "LWPOLYLINE"))))[/color]
[color=magenta] (TrimPline (ssname ssetPline 0) 50.0)[/color]
[color=magenta])[/color]

Please note that I have made some other correction to your code; you need also to add some validations to don't exceed polyline's length with the trim size.

Posted

In this case call the function above like this:

(setq basePLine (entlast))
;explode the polyline and parse resulted selection set
(command "_.EXPLODE" basePLine)
(setq ssetLines (ssget "_P"))

(while (> (sslength ssetLines) 0)
(setq myline (ssname ssetLines 0))     ;process first item in selection set
([b]TrimPline[/b] myline 5)

(setq ssetLines (ssdel myline ssetLines))   ;remove processed item
)

Posted

mircea,

understood - thanks for your help!

now i can continue to work on re-connecting the trimmed segments with straight lines and re-join them into a polyline. (practically replacing chamfer to work for all linetypes...)

martin

 

 

In this case call the function above like this:

(setq basePLine (entlast))
;explode the polyline and parse resulted selection set
(command "_.EXPLODE" basePLine)
(setq ssetLines (ssget "_P"))

(while (> (sslength ssetLines) 0)
(setq myline (ssname ssetLines 0))     ;process first item in selection set
([b]TrimPline[/b] myline 5)

(setq ssetLines (ssdel myline ssetLines))   ;remove processed item
)

Posted

Not sure why you want to achive exactly; are you aware that may apply the CHAMFER command a polyline like this?

 (setvar "CHAMFERA" 5.0)
(setvar "CHAMFERB" 5.0)
(command "_.CHAMFER" "_P" (entlast))

For sure, a good programming practice will be to retain user’s chamfer distances and replace them after processing.

 

 

Regarding the appearance of non-continuous line types on polyline please check the Ltype gen option of PLINE command.

Posted

CHAMFER is not working if the polyline contains arc segments, that's why i would like to explode it and draw them via a lisp routine.

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