Help in lisp please

Help in lisp please

onlineoffers1988
Contributor Contributor
5,363 Views
61 Replies
Message 1 of 62

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
Accepted solutions (3)
5,364 Views
61 Replies
Replies (61)
Message 2 of 62

Sea-Haven
Mentor
Mentor

This has been asked before and solutions provided, I have not provided any, if I can think of a correct search wording will post, else others will post solution. The only difference I can see quickly is the thickness of the connecting plines.

 

Maybe my 1st attempt "connect block to closest pline autocad lisp" you need to Google.

0 Likes
Message 3 of 62

onlineoffers1988
Contributor
Contributor

Hello

i searched for this issue before and i didn't find solution that i need ... can you help me in this lisp ... i attach DWG sample for the final drawing i want

thanks

0 Likes
Message 4 of 62

ВeekeeCZ
Consultant
Consultant

I believe that @hak_vz have had wrote a couple of this type of routines... but could be wrong.

 

BTW You wonder why you can't find anything similar in history by the keywords? Look at the mirror first, how informative your subject is!! 

0 Likes
Message 5 of 62

onlineoffers1988
Contributor
Contributor

really i have searched more and more and i didn't find my needs ... i know that the lisp i want is complex ... but i hope to help me

0 Likes
Message 6 of 62

hak_vz
Advisor
Advisor

@onlineoffers1988 

As @ВeekeeCZ mentioned in his reply, I have created at least  two or three similar codes in last two years. Unfortunately I don't have direct links to this posts. If I catch some time I'll try to write code for you. You can search this forum history to look for posts related to "connecting blocks" or similar. Due to some personal reasons I'm not in position to spend my spare time on writing codes, otherwise I would gladly jump in and try to mock up something for you.  

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
Message 7 of 62

Sea-Haven
Mentor
Mentor

Did you google using what I posted ? This is 1st option that appeared. Yes matches the other posters here.

SeaHaven_0-1668557333958.png

 

0 Likes
Message 8 of 62

onlineoffers1988
Contributor
Contributor

hello

really i search in the forum more ... your solutions didn't match with my lisp requirements ... my lisp contains 3 tasks that i mentioned in the post ... thank you for your time ... i'm really need help

0 Likes
Message 9 of 62

onlineoffers1988
Contributor
Contributor

Dear ... really i try all of this ... but this is not my requirements ... i want lisp to do the steps i mention in my post ... really i didn't find any lisp with my needs ... i post here because i have searched more and more for long time ... i didn't have any solution till now ... i'm sorry for this but really can anyone create this for me

0 Likes
Message 10 of 62

Moshe-A
Mentor
Mentor

@onlineoffers1988  hi,

 

What ddddd means?

What MDB means?

 

i'm not exactly of your design discipline, are we talking about lighting system? 

what's the point in calling blocks with meaningful names? isn't it the same mental effort to name a block as it should?

 

 

Moshe

 

 

 

 

0 Likes
Message 11 of 62

onlineoffers1988
Contributor
Contributor

MDB and dddd ... Just block names ... Not referring to anything... This is lighting drawing... But the lisp i need will run for any block names or any drawings... Just names

0 Likes
Message 12 of 62

onlineoffers1988
Contributor
Contributor

@ВeekeeCZ @Sea-Haven @Moshe-A @hak_vz @Kent1Cooper  Please help ... i find my solution to my lisp requirements but needs some edits please .... i want to edit as appear in my attached image ( 1st edit i want the route between main poly line and block with right angle  - 2nd i want lisp to flatten all polylines - 3rd i want the lisp to connect between each polyline from the block and the main route with fillet command to be the same as "sample DWG that i attached before") ... thank you very very very much

>>>>>>>>>>>>>>>

 

;;https://www.cadtutor.net/forum/topic/21484-i-search-for-offset-with-same-value-and-opposite-direction/#comment-175406
(defun c:ConnectBlocks ( / 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 Polyline Route ")
  (setq MyLineSS (ssget "_+.:E:S" (list (cons 0 "*LINE") ) ))

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

;;Get blocks
;;Select Route
  (princ "\nSelect End Blocks ")
  (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
      (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)
)

 

 

nnn.png111.png

0 Likes
Message 13 of 62

Sea-Haven
Mentor
Mentor

I can see how to do it manually not sure program wise, using draw line perp to, then fillet the line to the pline. Then Fillet Polyline to do all the little radius. A semi manual approach would give control over the sequence of lines.

SeaHaven_0-1668816648159.png

 

0 Likes
Message 14 of 62

Sea-Haven
Mentor
Mentor

Try this pretty sure can make better when doing fillet.

 

; Join blocks to parallel lines
; By Alan H Nov 2022

(defun c:dolights ( )
(setvar 'filletrad 30)
(setq obj (car (entsel "\nPick pline main cable ")))
(setq offpt (getpoint "\nPick point away from main for directions. "))
(setq off 0.0)
(setvar 'osmode 64)
(while (setq pt (getpoint "\npick block "))
(setq off (+ off 30.0))
(command "offset" off obj offpt "")
(setvar 'osmode 128)
(setq pt2 (getpoint pt "\nPick offset line "))
(setvar 'osmode 0)
(command "line" pt pt2 "")
(command "fillet" (entlast) (getpoint "pick fillet"))
(command "fillet" "P" (entlast))
(setvar 'osmode 64)
)
)
(c:dolights)
0 Likes
Message 15 of 62

onlineoffers1988
Contributor
Contributor

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

i show in this video the case of my lisp now >>> the edits i want  ... 1st edit i want the route between main poly line and block with right angle not slopped (see video)  - 2nd i want lisp to flatten all polylines (some polylines refused to filleted with each others)- 3rd i want the lisp to connect automatically between each polyline from the block and the main route with fillet command to be the same as in video

thank you very much

 

 

;;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
Message 16 of 62

Moshe-A
Mentor
Mentor

@onlineoffers1988  hi,

 

check this LSWIRE command.

 

Attached a LSWIRE.ZIP file containing lswire.vlx + lsw_supp.lsp - save these files in AutoCAD support files path (or your document folder). before rush to run it,  please follow these instructions:

 

lsw_supp.lsp defines your two blocks.

(setq ELECTRICPANEL "mdb" LIGHTINGFIXTURE "ddddd")

if you change the blocks name to some thing else, also specify it here. lswire tries to load this file and if it is fail, the above setting is default.

 

Command: LSWIRE
Select objects: <pick the Leading Path + the Electric Panel and all Lighting Fixtures>

Select objects: <pick pick pick...make sure you pick only one pline for the Leading Path>

Select objects: <press enter when done 😀>

Wiring offset <30.0000>:  <control of wiring offset, default of course is 30>

Preserve leading path <Yes>: < you can preserve the leading path for further review or key in  "No" to delete it>

 

lighting fixtures at perpendicular point to leading path is well handled, exception lighting fixtures (like the one left\down in your sample) may or may not handled and it depend on the case so do tests and if an update is needed i will try will fix it 😀

 

enjoy

Moshe

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Likes
Message 17 of 62

onlineoffers1988
Contributor
Contributor

first of all ... thank you very much for your reply ... i test the lisp ... works well but you can check attached video for this issue >>> 

0 Likes
Message 18 of 62

Moshe-A
Mentor
Mentor

@onlineoffers1988 

 

i'm sure this the result of the exceptional Lighting Fixtures so what i thought is to wire them to the Leading path with a diagonal segment and you will fix them manually.

 

Note:

lswire is using (vlax-curve-getClosestPointTo) function. what this function does is to find the close point on the Leading path and  if the lighting fixture is not close enough to what you thing it should be, it will snap to other close point on the pline, that's of course is depend on how the Lighting Path is laid.

 

why lsw_supp.lsp is not satisfactory?

 

Moshe

 

 

 

 

 

 

 

0 Likes
Message 19 of 62

onlineoffers1988
Contributor
Contributor

Dear @Moshe-A the lisp you give to me is excellent but restricted to spicific blocks also the issue of interference of polylines ... So can you try to edit my code with required edits that i mentioned there ... Many thanks for you

0 Likes
Message 20 of 62

Moshe-A
Mentor
Mentor

@onlineoffers1988 wrote:

Dear @Moshe-A the lisp you give to me is excellent but restricted to spicific blocks also the issue of interference of polylines ... So can you try to edit my code with required edits that i mentioned there ... Many thanks for you


what do you mean by that? in the same run you are using different classes of Fixtures?

 

0 Likes