Jump to content

HotOffTheGrill lisp


macros55

Recommended Posts

Posted (edited)

There is a VL function getdistatpoint so for the curved pline that part is easy provided the insertion point is on the pline.

 

Not sure which lisp your using, so pick line/Pline, pt1, pt2.

: (setq d1 (vlax-curve-getdistatpoint obj pt1))
87.8866210545767
: (setq d2 (vlax-curve-getdistatpoint obj pt2))
35.6222561586541
: (abs (- d1 d2))
52.2643648959226

You may need to use this also

(setq pt1 (vlax-curve-getclosestpointto obj pt1))

As sometimes the pick point is like 0.0000001 different, even with osnap on.

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

Sometimes objects(BLOCK,POINT,COGO POINT) do not coincide with the end points of the line. How can LISP do this? please see example dwg rev4 file in attached.

 

 

image.png.ae2d54a8b277fff21e13739c88922e1a.pngimage.thumb.png.bb6154f270a2068b0b1e72981fced7d0.pngimage.thumb.png.a1eb3b4e4ce7f2ec9eeddc86b55b8e73.png

HotOffTheGrill _ rev4.dwg

Edited by macros55
Link to comment
Share on other sites

Posted (edited)

Mr @Tsuky, Is it possible to adjust the touching distance of the object? If the object does not touch the line within 0.0000mm, the process does not occur. I think it would be better if the object's even touching distance was set to 0.05m.

image.thumb.png.30d10a6b7d7b5949e3990ec753bda5f1.pngimage.thumb.png.bc29baa0f3579cc2a45eef43cb511643.png

Edited by macros55
Link to comment
Share on other sites

On 5/22/2024 at 12:32 AM, macros55 said:

Mr Tsuky, Thank you very much for your interest, could you please make some arrangements? 

Try to change the line 232 in the code to

		OK (apply 'append (mapcar '(lambda (x) (mapcar '(lambda (zx) (equal (list (car x) (cadr x)) (list (car zx) (cadr zx)) 5E-02)) l_z)) (list pt_start pt_end)))

I haven't test 'it!

  • Like 1
Link to comment
Share on other sites

Posted (edited)

Sir . I updated it, the 0.05m edge capture mode worked, but I think there is a few missing. It does not create a yellow Polyline with the Block on the polyline. When only ARC is selected, it creates a yellow ARC. Also, The lisp it doesn't recognize it only when it's Line.

There is a problem with the arrow of the slopes because the arrow always points in the same direction, also the objects show different values depending on the first and second selection -1.55% /+ 1.55%. Would changing the arrow drawing to text <<</>>> be a solution?

Thank you for your generous help

Edited by macros55
Link to comment
Share on other sites

Posted (edited)

Because you want a yellow pline section working with curves in a pline it is difficult, a quick workaround is copy the pline say to right 200 then adjust the 2 points chosen points X+200, trim the pline both ends, change its layer so becomes yellow, move it back -200, all done. Removes all the headaches of trimming and remaking plines. 

 

No Code at this stage just a suggestion. Image shows idea.

 

image.png.0e0a769bf68c7c7bbee4a49c12c526ae.png

 

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

19 hours ago, macros55 said:

Sir . I updated it, the 0.05m edge capture mode worked, but I think there is a few missing. It does not create a yellow Polyline with the Block on the polyline. When only ARC is selected, it creates a yellow ARC. Also, The lisp it doesn't recognize it only when it's Line.

There is a problem with the arrow of the slopes because the arrow always points in the same direction, also the objects show different values depending on the first and second selection -1.55% /+ 1.55%. Would changing the arrow drawing to text <<</>>> be a solution?

Thank you for your generous help

Try this version.

Before to load it erase and purge your block "H-BLOCK" for a good execution.

foo.lsp

Link to comment
Share on other sites

Mr.Tsuky,

Could you please try this drawing yourself? rev5 dwg file

Unfortunately, it did not recognize some lines.
Also, when the object selection changes its location, the direction changes, but the direction  should follow the slope and always take the direction >>> towards the lower elevation.

 

Thank you very much.

HotOffTheGrill _ rev5.dwg

Link to comment
Share on other sites

Posted (edited)

Tsuky looking at copy the line arc pline etc out of the way and trim the ends of it off, then copy it back as yellow, so does not matter what the object is. See my image above working on a better 90 trim line at intersection pt. 

 

Code removed as it does not match latest sample dwg.

 

 

 

 

 

 

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

 

On 5/24/2024 at 4:26 PM, macros55 said:

Mr.Tsuky,

Could you please try this drawing yourself? rev5 dwg file

Unfortunately, it did not recognize some lines.
Also, when the object selection changes its location, the direction changes, but the direction  should follow the slope and always take the direction >>> towards the lower elevation.

 

Thank you very much.

HotOffTheGrill _ rev5.dwg 462.92 kB · 3 downloads

 

I think I have resolved your wishes.
However, I noticed for example that for a polyline with overlapping vertex, the new entity is not created.
Use OVERKILL on any that might cause problems.

 

foo.lsp

Edited by Tsuky
Update lisp code
  • Like 1
Link to comment
Share on other sites

Mr. Tsuky,


I think there are a few comments with the yellow line.
Could you please see  the attached drawing rev6?

 

I am grateful for your help.

foo rev6.dwg

Link to comment
Share on other sites

Posted (edited)

I can see now why the approach of looking at pline bulges etc.

 

There is no point at the 311.3/311.0 so the slope is incorrect just a comment. May be others.

image.png.b79b7931bc997ada77b77139cc4f3e19.png

 

A better approach to DO ALL may be to just walk along the line/pline and find vertices then look at the blocks at ends of each segment. There is a function that when getting a param at a pt if you use like 1, 2 etc its segments but 1.5, 2.5 etc  is the mid point of a segment. This is in some code I was looking at yesterday and solution by Kent Cooper over at forums/autodesk from a few years back.

 

I need to throw away what I did and have another think about it. I would use the segment idea and 0.5 steps. No need to work out bulges etc. 

 

defun getplineseg ( / elst ename pt param )
(setq elst (entsel "\nSelect pline segment: "))
(setq ename (car elst))
(setq pt (cadr elst))
(setq pt (vlax-curve-getClosestPointTo ename pt))
(princ (setq param (vlax-curve-getParamAtPoint ename pt)) )
(princ (setq preparam (fix param)) )
(princ (setq postparam (1+ preparam)) )
)


(setq pt1 (vlax-curve-getPointAtParam ename preparam))
(setq ptmid (vlax-curve-getPointAtParam ename (+ 0.5 preparam)))
(setq pt2 (vlax-curve-getPointAtParam ename postparam))

(setq pt (vlax-curve-getPointAtParam ename 0)) is start point. So just need how many segments.

 

Ie 9 vertices so 0-8.

 

Can then check is there a block at the ends (ssget pt '((0 . "insert" etc.

image.png.bb30a334fbb19e6212ef789006314c9a.png

Oh yeah do we really need the Yellow's or is that just for checking ?

 

Another problem but the 2 arcs are same radius. So extend 1st arc.

image.png.351ecf1ffec82bc72f4840e751ef9afb.png

Ps made into 9 vertices pline for testing.

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

Found another problem with one of your plines which may explain why some get skipped, a random pick and the pline looks like its only 2 points but a list reveals 4 points, in what I am doing causes a divide by zero problem. 

 

Lwpolyline ---------------------------------------------
                  Handle:  386B
           Current space:  Model
                   Layer:  CL
                   Color:  red
                Linetype:  ByLayer
          Polyline Flags:  Open
                    Area:  0.0000
               Perimeter:  258.0001
                Location:  X=   4706.4605  Y=   1516.2020  Z=   0.0000
                Location:  X=   4706.4605  Y=   1516.2020  Z=   0.0000
                Location:  X=   4937.2987  Y=   1400.9729  Z=   0.0000
                Location:  X=   4937.2988  Y=   1400.9729  Z=   0.0000

 

Try this, takes into account duplicate verices there is a bug which I will fix, ran out of time, select multiple plines. NOTE NO YELLOW linework. 

(defun c:grading ( / plent ent1 ent2 ent3 obj len pt1 pt2 vo-ord obj3 obj2 atts b2str1 b2str2 b1str1 b1str1)
(defun alg-ang (obj pnt)
  (angle '(0. 0. 0.)
     (vlax-curve-getfirstderiv
       obj
       (vlax-curve-getparamatpoint
         obj
         pnt
       )
     )
  )
)
(setvar 'attreq 1)
(setq oldaunits (getvar 'aunits))
(setvar 'aunits 3)
;(setq ss (ssget '((0 . "LWPOLYLINE")(cons 8 "CL"))))
;(repeat (setq j (sslength ss))
;(setq plent (ssname ss (setq j (1- j))))
(while (setq plent (car (entsel "\nPick a pline ")))
(setq obj1 (vlax-ename->vla-object plent))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
(setq lst '())
(setq x 0)
(setq pt1 (nth x co-ord))
(repeat (length co-ord)
(setq pt2 (nth (setq x (1+ x)) co-ord))
(if (and (equal (car pt1)(car pt2) 1e-4)(equal  (cadr pt1)(cadr pt2) 1e-4))
(princ)
(progn
(setq lst (cons (car pt1) lst))
(setq lst (cons (cadr pt1) lst))
)
)
(setq pt1 pt2)
)
(setq lst (reverse lst))
(if (= (length co-ord)(length lst))
(princ)
(progn
(setq var (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length lst)))) lst)))
(vla-put-coordinates obj1 var)
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent ))))
)
)
(setq x 0)
(setq b1 (ssname (ssget (nth x co-ord) '((0 . "INSERT"))) 0))
(setq obj2 (vlax-ename->vla-object b1))
(setq atts (vlax-invoke obj2 'Getattributes))
(setq b1str1 (atof (vlax-get (car atts) 'Textstring)))
(setq b1str2 (atof (vlax-get (cadr atts) 'Textstring)))
(setq k 0 spc 0.5  d1 0.0)
(repeat (- (length co-ord) 1)
(setq b2 (ssname (ssget (nth (setq k (1+ k)) co-ord) '((0 . "INSERT"))) 0))
(setq obj3 (vlax-ename->vla-object b2))
(setq atts (vlax-invoke obj3 'Getattributes))
(setq b2str1 (atof (vlax-get (car atts) 'Textstring)))
(setq b2str2 (atof (vlax-get (cadr atts) 'Textstring)))
(setq d2 (vlax-curve-getdistatpoint obj1 (nth k co-ord)))
(setq ptmid (vlax-curve-getPointAtParam plent spc))
(setq ang (alg-ang obj1 ptmid))
(setq diff (- b1str2 b2str2))
(if (>= diff 0.0)
(setq arrow "> > >")
(setq arrow "< < <")
)
(if (and (> ang (* pi 0.5)) (< ang (- (* pi 0.5)))) 
(setq ang (+ ang pi))
)
(setq arrow
  (if (and (> ang (* pi 0.5)) (< ang (- (* pi 0.5))))
  	(if (eq arrow "> > >") "< < <" "> > >")
  	(if (eq arrow "> > >") "> > >" "< < <")
  )
)
(setq len (- d2 d1))
(setq perc (strcat (rtos (* 100. (/ diff len)) 2 2) "%"))
(command "-insert" "H-BLOCK" "s" 1.0 ptmid ang (rtos len 2 2) arrow perc)
(setq d1 d2)
(setq b1str2 b2str2)
(setq spc (+ spc 1))
)
)
(princ)
)
(c:grading)

Found another problem will have to look at a workaround. This part of pline has a straight but no block then is a multi arc pline. This happens in a few locations.

 

image.thumb.png.96dca8a34243984c26f7423bf0c822b3.png

 

These drafting in consistencies make life hard. Can see why some are being labelled and others not.

 

Edited by BIGAL
Link to comment
Share on other sites

Posted (edited)

Mr. Bigal, I tried the code you wrote, unfortunately I couldn't get the result. I shared a video and picture attached. The LISP prepared by Mr. Tsuky works exactly as I want, LISP is doing the right thing. Even though there is another block in the middle, it only adds the yellow Polyline between the two selected blocks.
But it does not do the adding a yellow polyline in some places. It would be great if adding a yellow polyline solves the problem.
And when you select "Line", sometimes the slope arrow goes in the opposite direction, up to the elevation side, but the correct arrow should be down to the elevation side.
Thank you for your interest.

image.thumb.png.dfaade4795b6214c3a9dfacee885e982.png

 

Edited by macros55
Link to comment
Share on other sites

@macros55

In addition to block inserts, points and circles have been added. I do not have access to COGO points so I cannot handle this case.
LWPOLYLINE,LINE and ARC are accepted
I don't have the skills to produce a SPLINE part in lisp.
I think I solved the problem of overlapping vertices to produce the polyline part.
I updated the previous code.

  • Like 1
Link to comment
Share on other sites

Tsuky when looking at object ssget etc "Aecc_Cogo_point".

 

Did you find any of the problems I solved  helpful like the 4 point plines which should be 2.

  • Like 1
Link to comment
Share on other sites

Mr. Tsuky, Mr. BIGAL,

 

Thank you very much for your effort and good will.

 

Over time, I will report back to you the final working status using LISP.

 

 

Link to comment
Share on other sites

There is a post by I think by Exceed read today to do this task hopefully he will respond.

Link to comment
Share on other sites

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