Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Connecting blocks with line or arc for electrical plans

31 REPLIES 31
Reply
Message 1 of 32
jahbgd
4889 Views, 31 Replies

Connecting blocks with line or arc for electrical plans

Hi all,

 

I have been searching something similar all over web but no luck.

 

I need lisp that would ask for point 1 (specified by user) , insert block1 (ie. light switch), than ask point 2, insert block2 (ie. pendant light), draw a line (or an arc) connecting two, ask for point3, insert block3 (ie. light switch, again), connects it with block 2 and so on...

 

Hope I was clear with idea and it is possible to make...

I should start working on electrical plans and since so many people before me had same problem with this i hope someone already have it.

 

Thanks and hoping for some help.

 

Cheers

Jan 

31 REPLIES 31
Message 2 of 32
3wood
in reply to: jahbgd

I think the workflow is not as smooth as you described. There will be different lighting legends, curved route, breaks or arc at intersection, etc.

 

Message 3 of 32
jahbgd
in reply to: 3wood

I am sure there is no easy solution , esspecialy if you wat to choose light symbols, but one of the workarounds would be to have all light symbols in one block with several visual states. In that case routine would deal with connecting blocks with lines and the morfing them into arcs. You would have to manually change - select state for each block, but still would be helpful. Also idea for connecting line- "cord" could be arc constructed from block insert points and end point of a new temporary line set as perpendicular of certan lenght from midpoint.( see sketch attached- easy to draw , hard to explain)

 

Is this too complicated?

 

 

El_pln_lsp.JPG

Message 4 of 32
scot-65
in reply to: jahbgd

The insert point for our switches is different to the place the wire is attached to. However, most ceiling symbols will share insert point to wire point but not for the wall symbols.

With that said, programming an auto-wire program will involve creating a selection set (entnext) and iterating thru the set to determine where to place the wire's ends based on the block name and it's rotation value. This will get rather involved as each symbol will require a closer look.

Another mention is when new symbols are added, the program will have to be edited to accommodate these new symbols names and starting points for the wire.

I'll throw this quick and dirty one at you - Continuous Wiring:

(defun c:CW ( / a )
(graphscr)
(setq usercw (getpoint "Continuous Wiring \nSpecify start point of arc: "))
(while usercw
(setq a (getpoint usercw "\nSpecify second point of arc: "))
(if a
(progn
(command "arc" usercw a pause)
(setq usercw (getvar "lastpoint"))
);progn
(setq usercw nil)
);if
(setq a nil)
);while
);endCW

??

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 5 of 32
hmsilva
in reply to: jahbgd


@jahbgd wrote:

I am sure there is no easy solution , esspecialy if you wat to choose light symbols, but one of the workarounds would be to have all light symbols in one block with several visual states. In that case routine would deal with connecting blocks with lines and the morfing them into arcs. You would have to manually change - select state for each block, but still would be helpful. Also idea for connecting line- "cord" could be arc constructed from block insert points and end point of a new temporary line set as perpendicular of certan lenght from midpoint.( see sketch attached- easy to draw , hard to explain)

 

Is this too complicated?


Hi Jan,

 

I have an old code, and with some modifications, will do the arcs connecting the inserted blocks.

'perpendicular of certan lenght from midpoint'

The lenght will be always the same, or will have a relation (1/3 or 1/4) from the distance between blocks?

 

Henrique

 

EESignature

Message 6 of 32
jahbgd
in reply to: scot-65

Hi Scot,

 

Thanks for the answer. I was out of office for a few days. 

 

In terms of arcs it is pretty close. The thing is that you need to have that middle click, but it is ok. I will be using it definutely.

 

Also, I realized that making the whole thing with inserting blocks etc too complicated, even in planning stage, not to mention programming.

 

Thanks!

Jan

Message 7 of 32
jahbgd
in reply to: hmsilva

Hi H,

 

As I said, I was out of office for a few days. 

 

If you can share that code , maybe it will be useful.

 

Thanks!

Jan

Message 8 of 32
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

.... The thing is that you need to have that middle click, but ....  Also, ... the whole thing with inserting blocks etc too complicated....


For already-inserted Blocks, here's a way to make continuous Arcs connecting them that doesn't require "that middle click," but only the picking on each Block in series.  It doesn't use a constant bulge distance at the midpoint of each Arc as mentioned earlier [which would result in very different degrees of bulge at different lengths], but rather a constant starting-direction angle relative to the angle between the endpoints, for a consistent degree of bulge.  I picked what looks to me like a reasonable degree of bulginess, but you can adjust that.  It always bulges in the generally more upward direction.

 

Be aware that it's possible it will Snap to the insertion point of some nested entity within a given Block, if there are any such things, rather than to that of the Block itself, so if that's a possibility, be watchful while using it -- you can see what it's going to snap to before you pick.  And it should, of course, be fleshed out to save the OSMODE value first and reset it later, etc., but see what you think:

 

(defun C:WA (/ pt1 pt2); = Wiring Arcs
  (setvar 'osmode 64); Insertion
  (setq pt1 (getpoint "\nStart point for Arc(s): "))
  (while (setq pt2 (getpoint "\nEnd of Arc: "))
    (command
      "_.arc" pt1 "_e" pt2 "_direction" ; [spelling out "_end" is taken as Osnap call]
      (angtos (apply (if (> (car pt2) (car pt1)) '+ '-) (list (angle pt1 pt2) (/ pi 5))))
        ; change 5 above to lower number for more bulge, higher for less
    ); command
    (setq pt1 pt2); for start of next Arc
  ); while
); defun

Kent Cooper, AIA
Message 9 of 32
hmsilva
in reply to: jahbgd


@jahbgd wrote:

If you can share that code , maybe it will be useful.


Hi Jan,

of course I will share the code, can you just answer this question please...

 

'The lenght will be always the same, or will have a relation (1/3 or 1/4) from the distance between blocks?'

 

Henrique

 

EESignature

Message 10 of 32
jahbgd
in reply to: hmsilva

Ahh, sorry I thought you will leave me to modify it (which i am not sure that i would manage) 🙂 

 

I guess it will be better to have 1/4... I think i will be able to modify ratio to 1/3 ...

 

Thanks

Jan 

Message 11 of 32
jahbgd
in reply to: Kent1Cooper

Hi Kent,

 

Thanks for the effort. It works great and in the more timesaving manner. The catch with osnapmode is cool. At first i didnt realize that osnap works, because i want clicking near blocks 🙂 but than i realizet that "64" is INSertion.

 

Best

Jan

Message 12 of 32
hmsilva
in reply to: jahbgd


jahbgd wrote:

I guess it will be better to have 1/4... I think i will be able to modify ratio to 1/3 ...


Jan,

 

you'll need to change the "H:\\your\\block\\library\\path\\" to the correct path...

 

(defun c:demo (/ *error* insrt -ang ang ang1 ang2 blk blk1 blk2 pt1 pt2 pt3 pt4)

  (defun *error* (msg)
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )
    (princ)
  )

  (defun insrt (/ ans blk flag)
    (setq flag t)
    (while flag
      (if (or blk
              (/= (setq blk (getvar 'INSNAME)) "")
          )
        (progn
          (initget "Blockname")
          (setq ans (getpoint
                      (strcat "\n Specify insertion point for '" blk "' or [Blockname] <exit>:")
                    )
          )
        )
        (setq ans "Blockname")
      )
      (cond ((= 'list (type ans))
             (command "-insert" blk ans)
             (while (> (getvar 'cmdactive) 0)
               (command "\\")
             )
             (setq flag nil)
             (entlast)
            )
            ((and ans (wcmatch ans "Blockname"))
             (if (not (setq blk (getfiled "Select a block"
                                          "H:\\your\\block\\library\\path\\"
                                          "dwg"
                                          0
                                )
                      )
                 )
               (setq flag nil)
             )
            )
            ((null ans)
             (princ "\n Exiting...")
             (setq flag nil)
            )
      )
    )
  )

  (setq blk (entlast))
  (if (and (setq blk1 (insrt))
           (not (eq blk blk1))
           (setq pt1 (trans (cdr (assoc 10 (entget blk1))) 0 1))
           (setq blk2 (insrt))
      )
    (while (and (not (null blk2))
                (not (eq blk1 blk2))
           )
      (setq pt2  (trans (cdr (assoc 10 (entget blk2))) 0 1)
            pt3  (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2.0))
            ang  (angle pt3 pt2)
            -ang (angle pt2 pt3)
      )
      (grvecs (list -2 pt1 pt3 pt3 pt2))
      (if (setq pt4 (getpoint pt3 "\n Pick arc side: "))
        (progn
          (setq ang1 (angle pt3 pt4))
          (if (< ang -ang)
            (if (<= ang ang1 -ang)
              (setq ang2 (/ (+ -ang ang) 2))
              (setq ang2 (+ (/ (+ -ang ang) 2) pi))
            )
            (if (<= -ang ang1 ang)
              (setq ang2 (/ (+ -ang ang) 2))
              (setq ang2 (+ (/ (+ -ang ang) 2) pi))
            )
          )
          (command "_.redraw")
          (command "_.arc" "_NONE" pt1 "_NONE" (polar pt3 ang2 (/ (distance pt1 pt2) 3) "_NONE" pt2)
          (setq pt1  pt2
                blk1 blk2
                blk2 (insrt)
          )
        )
        (command "_.redraw")
      )
    )
  )
  (*error* nil)
  (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 13 of 32
hmsilva
in reply to: jahbgd

Jan,

 

I can no longer edit my previous post, so you'll need to add one ")" in

 (command "_.arc" "_NONE" pt1 "_NONE" (polar pt3 ang2 (/ (distance pt1 pt2) 3)) "_NONE" pt2)

 

Henrique

EESignature

Message 14 of 32
jahbgd
in reply to: hmsilva

Henrique,

 

Thanks for message and sorry for late answer. 

 

I tried routine, but I find it a bit confusing. 

It asks for a block(file) so there is a problem with basepoint, as it doesent use block basepoint but from file (i guess), and then there is connecting line problem, related to basepoint issue.

 

Sorry for the trouble, but if you decide to spend more time on this, i would suggest eliminating scale block part, maybe leave rotate, and in generating arcs, make fix ratio.I my personal opinion, it has too many option to select every time you use routine.

 

Anyhow thanks again for looking into this.

 

Cheers

Jan 

Message 15 of 32
hmsilva
in reply to: jahbgd


@jahbgd wrote:

Henrique,

 

Thanks for message and sorry for late answer. 

 

I tried routine, but I find it a bit confusing. 

It asks for a block(file) so there is a problem with basepoint, as it doesent use block basepoint but from file (i guess), and then there is connecting line problem, related to basepoint issue.

 

Sorry for the trouble, but if you decide to spend more time on this, i would suggest eliminating scale block part, maybe leave rotate, and in generating arcs, make fix ratio.I my personal opinion, it has too many option to select every time you use routine.


You're welcome, Jan!

 

- 'I tried routine, but I find it a bit confusing.'

  What is the command you use to insert the blocks?

  Via tool Palettes?

  Command 'insert'?

 

- Block insertion point...

   How is your block library defined?

   Each block is an independent file, or all the blocks are in one file?

 

_ 'i would suggest eliminating scale block part, maybe leave rotate, and in generating arcs, make fix ratio.I my personal opinion, it has too many option to select every time you use routine.'

   Eliminate the scale, no problem.

   The arcs have a fix ratio, the user have to pick one side for the arc...

  

Henrique

EESignature

Message 16 of 32
ВeekeeCZ
in reply to: hmsilva

Hi, since I'm little sick.. I tried another method. You gonna need an extra line or polyline to show it's direction. Then you select BLOCKs or CIRCLEs and that polyline all together...

 

wire.png

Message 17 of 32
ВeekeeCZ
in reply to: ВeekeeCZ

Little change to make all bunges same high.

Message 18 of 32
adminJ7PFV
in reply to: Kent1Cooper

Hi, 

 

This is a helpful command for me. However, when i use this command my snap settings are unchecked. Is there a way to keep my snaps checked when I use this command.

 

Thank you. 

 

Regards, 

Anesah

 

 

Message 19 of 32
Kent1Cooper
in reply to: adminJ7PFV


@adminJ7PFV wrote:

... when i use this command my snap settings are unchecked. Is there a way to keep my snaps checked when I use this command.

.... 


Remove this line:

 

  (setvar 'osmode 64); Insertion

 

[which was part of the OP's process, to lock onto each Block's insertion point], and whatever your current Osnap settings are will remain.

Kent Cooper, AIA
Message 20 of 32
Kent1Cooper
in reply to: adminJ7PFV


@adminJ7PFV wrote:

.... when i use this command my snap settings are unchecked. Is there a way to keep my snaps checked when I use this command.

.... 


Come to think of it....

 

If by that you mean that you want your Osnap mode combination restored after running the routine, but you want it to use Insertion mode only during the routine [because you're wiring Blocks, like the OP], this will do that:

 

(defun C:WA (/ *error* osm pt1 pt2); = Wiring Arcs
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'osmode osm)
  ); defun - *error*
  (setq osm (getvar 'osmode))
  (setvar 'osmode 64); Insertion
  (setq pt1 (getpoint "\nStart point for Arc(s): "))
  (while (setq pt2 (getpoint "\nEnd of Arc: "))
    (command
      "_.arc" pt1 "_e" pt2 "_direction" ; [spelling out "_end" is taken as Osnap call]
      (angtos (apply (if (> (car pt2) (car pt1)) '+ '-) (list (angle pt1 pt2) (/ pi 5))))
        ; change 5 above to lower number for more bulge, higher for less
    ); command
    (setq pt1 pt2); for start of next Arc
  ); while
  (setvar 'osmode osm)
); defun

 

Or, if you want to add Insertion mode to your Osnap modes for snapping to Block insertion points, if it's not already among them, but still keep other modes that you have running, replace this line above:

 

  (setvar 'osmode 64); Insertion

 

with this:

  (setvar 'osmode (logior 64 (getvar 'osmode))); add Insertion if not already there

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost