Help in lisp please

onlineoffers1988
Contributor
Contributor

Help in lisp please

onlineoffers1988
Contributor
Contributor

hello

i want help for creating lisp for me please ... the lisp will do these functions

1- as the attached image if i have block with yellow at right and some green blocks 1a.png

2- i want when i launch the lisp to ask me to draw poly line that i want as in image 2

2a.png

3- after that when i draw this path with polyline and press enter the lisp ask me to choose blocks that i want to connect to this polyline and i will choose one by one or multiple blocks then after choosing the blocks and press enter ... the lisp will offset the main polyline that i draw and connect every polyline with the basepoint of the blocks that i choose sequentially as appear in this image (attached DWG)

5a.png

can anyone help me please

0 Likes
Reply
Accepted solutions (3)
3,735 Views
61 Replies
Replies (61)

onlineoffers1988
Contributor
Contributor

@Moshe-A thank you very much ... but keep in your mind that i offer to pay for you at private message before and you didn't reply on me ... thank you for your effort ... also i don't mention that is a life an death case   ... 

And advice to you from an older brother... When you do something free of your own will... Do not feel that the one who took this service from you is a beggar... The origin in this wonderful forum is to help... Do not help and give credit to those you helped and finally... Really I apologize for my entire post if it was going to bleed one of you and you saw that it was useless

0 Likes

Moshe-A
Mentor
Mentor

@onlineoffers1988 



i'm also sorry that this went to this place but i disagree with your interpretation of how this Forum should work.
the helpers are here totally voluntarily helping to the best of their judgment have the right to decide to who they help and how and what they want to give. it is the OP decision if he wants (or not) to get this help.

and for the private message sorry i do know look there and if i did? my answer (sorry) would be also no.

 

you got a perfect solusion for your request and this was the full help service from this forum more over i even voluntarily suggest to keep updating it in future if it needed. the fact that you so badly insit to hold the lsp indicates your other intensions.

 

this was my last respond on this case.

 

good bye friend

Moshe

 

0 Likes

onlineoffers1988
Contributor
Contributor

@Moshe-A thank you again my friend but i want to clarify issue for these words "the fact that you so badly insit to hold the lsp indicates your other intensions" ... why i were insist lsp file ... really i were suffer from vlx files with my cad versions and with my computer more and more at home and at work ... so i always deal with .lsp files ... you can check these links that proved vlx may make problems with cad versions and that i fall in before 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vlx-files-works-with-2007-and-2010-v...

https://adndevblog.typepad.com/autocad/2017/04/digitally-signed-vlx-files-are-not-working-in-autocad...

.... but ok if you still thinking about me that i have another intensions ... i respect all opinions ... i will use your lisp with vlx version and if any error faces me i will contact you again if you permit this

best regards

thanks

0 Likes

hak_vz
Advisor
Advisor

@onlineoffers1988 

Main idea of this forum is to teach. With new members most of us "older" members will provide open code and make few changes if needed. Basically what we want to see is your own code or even a pseudo-code about how you intent to solve your problem. There are members that started as with continuous requests for code and didn't show any will to learn basics. And there are some that started to write programs from very basic functions to complex ones, To those ones I'm always willing to share my time.

Unfortunately in this forums we have gazillions of posts with some wonderful code and cleaver solutions that are buried under repetitive requests.

For your request, I would not use lisp at all. Combination of commands offset and trim and drawing polylines with perpendicular osnap is enough. At the end of the day, you'll spend same amount of time while picking block connection sequences as to create offsets of main line and place perpendicular connections to it.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

Sea-Haven
Mentor
Mentor

This request is double posted which does not help.

 

"For your request, I would not use lisp at all. Combination of commands offset and trim and drawing polylines with perpendicular osnap"

 

That is exactly what I posted in one of the posts. A lisp version of the manual steps, compare to full manual time in doing the request. Yes a time saver and always in correct order as you pick.

0 Likes

john.uhden
Mentor
Mentor

@onlineoffers1988  et al.

I think I've developed an observation about this topic.

It seems to me that a lot of effort from the masters around here has been spent attempting to provide some magic to a problem that is infrequent and easily solved with OOB AutoCAD commands.  My usual suggestion is to learn to use what you have already and budget the time necessary to complete the task .

Especially when no one else here is benefitting from the offered solutions.

Surely lesser paid personnel can be taught to perform the task when needed.

John F. Uhden

0 Likes

calderg1000
Mentor
Mentor

Dear @onlineoffers1988 

I really appreciate your interest in asking for help. Although you do not show your progress but it is a motivation for me. Even if you don't really like the previous scope I showed you. Here I show you another approach, which can improve your workflow. You just have to take into account selecting the blocks in the order that I show you previously.
I leave it to you to improve the lines of the corners. I showed you the idea in the previous routine. I hope you can help me with it. it is still possible to improve something more.
Best regards.

(defun c:Polum (/ s sn of sv pb p pr i lp px lpf snv)
  (setq s  (ssget "+.:E:S" '((0 . "lwpolyline")))
        sn (ssname s 0)
        of (getdist "\nEnter Polyline Offset: ")
  )
  (while
    (setq sb (ssget "+.:E:S" '((0 . "Insert")))
          pb (cdr (assoc 10 (entget (ssname sb 0))))
          p  (vlax-curve-getclosestpointto sn pb)
          pr (vlax-curve-getparamatpoint sn p)
          i  (1+ (fix pr))
    )
     (setq
       lp ()
     )
     (repeat i
       (setq px  (vlax-curve-getpointatparam sn (setq i (1- i)))
             lp  (cons px lp)
             lpf (cons pb (cons p (reverse lp)))
       )
     )
     (setq snv (vlax-ename->vla-object sn)
     )
     (LWPoly lpf)
     (vla-offset snv of)
     (setq sn (entlast))
     (command "_.fillet" "_polyline" sn)
     (vla-erase snv)
  )
)
;_
(defun LWPoly (lst)
  (entmakex
    (append
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 90 (length lst))
        (cons 70 0)
      )
      (mapcar (function (lambda (p) (cons 10 p))) lst)
    )
  )
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes

onlineoffers1988
Contributor
Contributor

thank you for your help ... really appreciate your effort ... but still at some complex drawings the selecting blocks into order issue is not applicable and so hard ... but i will try to learn programming and i will try to develop this excellent code that you provide ... thank you very much

0 Likes

onlineoffers1988
Contributor
Contributor

@calderg1000  ... i think the trick to solve block order issue is to define the starting point of the route to the lisp (we can add option to make user select the starting point of route) ... so when the offset done and start to link with block, the route will begin from starting point and every block the route meets will do offset and link with the block with its order ... also small trick i note ... why offset done at one side of the route ... if we can make the offset for both sides i think this will help more at the block order issue 

is this right??? 

0 Likes

calderg1000
Mentor
Mentor

 

Dear @onlineoffers1988 , what you suppose is very true. The direction of the route is important. to connect the blocks following a preset order.
I cannot confirm if the compensation on both sides is the most correct. In the tests that I do for me, it works well compensating for only one side.
I'll be working on it, I hope to improve the code soon.

Regards.


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes

onlineoffers1988
Contributor
Contributor

Dear @calderg1000 another thing that i noticed that your lisp works with way that may need to updated ... i will explain >>> your lisp routine is ... 1. pick main route >>> 2. pick the block >>> 3. offset and connect the block >>> 4. return again to pick another block >>> 5. offset and connect the selected block >>> and so on .... what's your opinion in the following routine ... 1. Pick main route >>> 2. pick start point >>> 3. pick all blocks one by one >>> 4. offset for the main route with the no. of blocks-1 (as the main line will be used also) >>> 5. draw polyline from block base point and nearest offset polyline (prefer to be not diagonal) >>>6. fillet each two polylines together (the nearest main and from block) .... 

already the following lisp can done point 1, 3, 4 and 5 (for this point the pl is diagonal at few blocks as you know) >>> what's your opinion in this suggestion?? 

;;https://www.cadtutor.net/forum/topic/21484-i-search-for-offset-with-same-value-and-opposite-direction/#comment-175406
(defun c:HomeRun ( / acount MyLineSS MyBlockSS of MyOffSS)
;;Undo
  (defun *error* ( msg )
    (and undo (vla-EndUndomark doc))
    (or
      (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
      (princ (strcat "\n** Error: " msg " **"))
    )
    (princ)
  )

;;https://autocadtips1.com/2011/10/13/autolisp-perpendicular-to-entity/
;; by sinc @ the Swamp 07/22/2004
;; Repeatedly draws a line from a pick point perpendicular
;; to a selected object
  (defun perp2ent ( MyLine MyPoints / entity pt acount)
    (setq acount 0)
    (while (< acount (length MyPoints))
        (setq pt (nth acount MyPoints))
        (entmake (list '(0 . "LINE") (cons 10 (trans pt 1 0))
        (cons 11 (vlax-curve-getClosestPointTo MyLine (trans pt 1 0)))) ;_ list
      ) ;_ entmake
      (setq acount (+ acount 1))
    ) ;_ while
    (princ)
  ) ;_ defun

;; Loop layers selection
;;Select Route
  (princ "\nSelect Home Run Route ")
  (setq MyLineSS (ssget "_+.:E:S" (list (cons 0 "*LINE") ) ))
  (command "_.fillet" "_polyline" (entlast))

;;Get Offset
  ;;(setq of 2.5) ; default offset, 2.5. Maybe work out as fraction of line length
(setq of (getdist "\nSpecify Distance between Lines: ")) ; User selects distance

;;Get blocks
;;Select Route
  (princ "\nSelect one Block from every circuit ")
  (setq MyBlockSS (ssget (list (cons 0 "INSERT") ) ))
  (setq BlockSelected (sslength MyBlockSS) )

;; Do Offset
    (setq acount 1) ;; 1 so that it draws correct no of lines
    (setq side 1)
    (while (< acount (sslength MyBlockSS))
      (setq offset (* acount of side) )
      (setq VlaOb (vlax-ename->vla-object (ssname MyLineSS ( - acount 1))))
      (vla-offset VlaOb offset ) ;; offset line 1
      (setq MyLineSS (ssadd (entlast) MyLineSS)) ;; add offset to selection set
      (command "_.fillet" "_polyline" (entlast))
      (setq side (* side -1))
      (setq acount (+ acount 1))
    ) ; end while

  (setq MyLine (ssname MyLineSS 0))
  (setq acount 0)
  (setq MyPoints (list))
  (while (< acount (sslength MyBlockSS))
    (setq MyPoints (append MyPoints (list (cdr (assoc 10 (entget (ssname MyBlockSS acount))))) ))
    (setq acount (+ 1 acount))
  )
  (perp2ent MyLine MyPoints)

;;Finish
;  (vla-EndUndoMark doc)
  (princ)
)

 

 

 

0 Likes

calderg1000
Mentor
Mentor
Accepted solution

Dear @onlineoffers1988 

Try this code with some improvements. I tried it and it works fine for me, I show you a video of its operation.
For more complex routes, the direction of the route and the order of selection of the blocks are very important.
At the moment I can't reach the magic of @hak_vz , to make it work with a Click

 

 

(defun c:Polum3 (/ s sn of sv pb p pr i lp px lpf pint snv)
  (command-s "_.pline")
  (setq pl (entlast)
        s  (ssadd pl)
        sn (ssname s 0)
        of (getdist "\nEnter Offset Pol: ")
  )
  (while
    (setq sb (ssget "+.:E:S" '((0 . "Insert")))
          pb (cdr (assoc 10 (entget (ssname sb 0))))
          p  (vlax-curve-getclosestpointto sn pb)
          pr (vlax-curve-getparamatpoint sn p)
          i  (1+ (fix pr))
    )
     (setq
       lp ()
     )
     (setq ang (angle pb p))
     (if
       (or (= ang 0) (= ang (* 0.5 pi)) (= ang (* 1.5 pi)))
        (repeat i
          (setq px  (vlax-curve-getpointatparam sn (setq i (1- i)))
                lp  (cons px lp)
                lpf (cons pb (cons p (reverse lp)))
          )
        )
        (progn
          (setq pint (list (car pb) (cadr p)))
          (repeat i
            (setq px  (vlax-curve-getpointatparam sn (setq i (1- i)))
                  lp  (cons px lp)
                  lpf (cons pb (cons pint (cons p (reverse lp))))
            )
          )
        )
     )
     (setq snv (vlax-ename->vla-object sn)
     )
     (LWPoly lpf)
     (command "_.fillet" "_polyline" (ssadd (entlast)))
     (vla-offset snv of)
     (setq sn (entlast))
     (command "_.fillet" "_polyline" sn)
     (vla-erase snv)
  )
)
;_ 
(defun LWPoly (lst)
  (entmakex
    (append
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (cons 100 "AcDbPolyline")
        (cons 90 (length lst))
        (cons 70 0)
      )
      (mapcar (function (lambda (p) (cons 10 p))) lst)
    )
  )
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Š’eekeeCZ
Consultant
Consultant
Accepted solution

Perhaps something like this.

onlineoffers1988
Contributor
Contributor

thank you for your great effort @calderg1000 i will use this great lisp at simple drawing that it's easy to define the route ... 

0 Likes

onlineoffers1988
Contributor
Contributor

thank you very much @Š’eekeeCZ working well for all drawings simple and complex  ... but the join and fillet between two polylines (from block and main route) not done ... i think the problem at this line 

(vl-cmdf "_.join" n a "")

this is final edit šŸ™

thanks 

0 Likes

onlineoffers1988
Contributor
Contributor

@Š’eekeeCZ i try this 

(command "_.fillet" n a "")

instead of this 

(vl-cmdf "_.join" n a "")

when the lisp run it works but the two polylines have this problem >>> Two entities are non coplanar

i suggest to add flatten command to make the two polylines at z=0 ... so if we able to flat the two lines then the command of fillet will work and fillet the two pl ... is this right sir??

 

0 Likes

onlineoffers1988
Contributor
Contributor

Solveeeeeeeeeeed .... thanks >>> i add this in the beginning of the lisp ... 

   (vlax-for b (vla-get-blocks (setq kk (vla-get-activedocument (vlax-get-acad-object))))
       (if (= :vlax-false (vla-get-isxref b))
           (vlax-for oo b
               (if (vlax-write-enabled-p oo)
                   (foreach e '(1e99 -1e99)
                       (vlax-invoke oo 'move '(0.0 0.0 0.0) (list 0.0 0.0 e))
                   )
               )
           )
       )
   )
   (vla-regen kk acallviewports)
   (princ)
(vl-load-com) (princ)

this make all object at the same z=0 ... and the lisp works well after that

thanks for all

Š’eekeeCZ
Consultant
Consultant
Accepted solution

Here's the version without those commands.

For some reason I never had a problem with those blocks, so I used the commands. IMHO you should fix your drawings anyway, regardless of whether the routine can handle them or not. But it shouldn't be a task for this routine.

 

 

Sea-Haven
Mentor
Mentor

Not obvious unless look a bit harder blocks were at 0.0 and 1e-15.

0 Likes

Gobel_A
Enthusiast
Enthusiast

@Š’eekeeCZ  I'am getting an error "undefined function" with getpropertyvalue function in wiring.lsp (do not use Acad, but ZW Cad). I tried to rewrote it to vlax_get_property but still getting an error. Is there any workaround ?

0 Likes