Blocks in nodes with more than 2 lines

Blocks in nodes with more than 2 lines

Dan-Rod
Advocate Advocate
2,131 Views
31 Replies
Message 1 of 32

Blocks in nodes with more than 2 lines

Dan-Rod
Advocate
Advocate

Hello

 

I want to know how to add blocks to nodes where more than 2 lines come out, I have 2 blocks, one exclusive for 3 lines (3R), and another for more than 4 lines that come out of the same node (4R).

 

Attached file with blocks and an example of lines already with overlapping blocks.

 

I hope you can support me.

 

0 Likes
Accepted solutions (4)
2,132 Views
31 Replies
Replies (31)
Message 2 of 32

Kent1Cooper
Consultant
Consultant

@Dan-Rod wrote:

.... another for more than 4 lines ....

 


I think, from the drawing, that the wording above should really be "... another for 4 or more lines ..." -- is that correct?

Kent Cooper, AIA
0 Likes
Message 3 of 32

Dan-Rod
Advocate
Advocate

It is correct, that's right, for 4 or more lines.

0 Likes
Message 4 of 32

Kent1Cooper
Consultant
Consultant

So what would be your process?  The command asks you to select a bunch of Lines?  It finds all Lines in the drawing itself, without User selection?  Something else?  Restricted to [a] particular Layer[s]?  All Blocks at scale of 1, or affected by the drawing scale?  All at rotation of 0, or affected somehow by the directions of the Lines?  Some other criteria?  Etc.

Kent Cooper, AIA
0 Likes
Message 5 of 32

Dan-Rod
Advocate
Advocate

So,
What would your process be?
Automate the placement of blocks at points where there are more than 3 lines, the idea is that this block represents a tool that will distribute wiring, there are only 2 tools to distribute in 3 and four directions.
Does the command ask you to select a bunch of lines?
If it is possible to detect the point where there are more than 3 lines and insert taking this reference criterion.
Find all the Lines in the same drawing, without User selection?
Preferably find all nodes and insert automatically, if you can not go selected.
Anything else?
Restricted to [one] particular layer[s]?
No, only take into account the node where there are more than 3 lines
All Blocks at scale 1, or affected by drawing scale?
1:1 scale
Everything in 0 rotation, or affected in some way by the directions of the Lines?
Rotation 0
Any other criteria? Etc.

0 Likes
Message 6 of 32

ronjonp
Advisor
Advisor

@Dan-Rod Your block insertion points are not it in the center of the circles?

ronjonp_0-1680544189486.png

Here's a quick one to place text that denotes how many common points are found.

 

(defun c:foo (/ i m p r s)
  (cond	((setq s (ssget '((0 . "LINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq r (cons (list (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e)) r))
	 )
	 (setq r (apply 'append r))
	 (while	(setq p (car r))
	   (setq r (cdr r))
	   (setq m (vl-remove-if-not '(lambda (x) (equal p x 1e-4)) r))
	   (if (> (setq i (1+ (length m))) 2)
	     (progn (entmake (list '(0 . "TEXT")
				   '(100 . "AcDbEntity")
				   '(67 . 0)
				   '(8 . "Junction_Label")
				   '(100 . "AcDbText")
				   (cons 10 p)
				   '(40 . 7.5)
				   (cons 1 (strcat (itoa i) "R"))
				   '(50 . 0.)
				   '(41 . 1.)
				   '(51 . 0.)
				   '(71 . 0)
				   '(72 . 1)
				   (cons 11 p)
				   '(100 . "AcDbText")
				   '(73 . 2)
			     )
		    )
		    (foreach x m (setq r (vl-remove x r)))
	     )
	   )
	 )
	)
  )
  (princ)
)

 

ronjonp_1-1680544283225.png

 

0 Likes
Message 7 of 32

Kent1Cooper
Consultant
Consultant

You need to redefine the Blocks for the correct scale [they're inserted at scales of 0.0394 in the sample drawing, not 1], and to have their insertion points at their centers [they're wacky off in the sample drawing].  But given those corrections, this is one way to do it [minimally tested]:

(defun C:TEST (/ liness n ldata ptlist thispt thisss)
  (if (setq liness (ssget "_X" '((0 . "LINE")))); add Layer filter if desired
    (progn ; then
      (repeat (setq n (sslength liness)); make list of all Line endpoints
        (setq
          ldata (entget (ssname liness (setq n (1- n))))
          ptlist (cons (cdr (assoc 10 ldata)) ptlist); add start point
          ptlist (cons (cdr (assoc 11 ldata)) ptlist); add end point
        ); setq
      ); repeat
      (while ptlist
        (setq
          thispt (car ptlist); first remaining
          thisss (ssget "_C" (polar thispt (/ pi 4) 2) (polar thispt (* pi 1.25) 2) '((0 . "LINE,INSERT")))
            ;; 2 argument based on sample drawing AS CORRECTED, to find Block as well as Lines if present
        ); setq
        (if
          (and
            (not (ssget "_P" '((0 . "INSERT") (2 . "3R,4R")))); not already a Block there
            (> (sslength thisss) 2); more than 2 Lines meet there
          ); and
          (command "_.insert" (if (= (sslength thisss) 3) "3R" "4R") "_non" thispt "" "" ""); then
        ); if
        (setq ptlist (vl-remove thispt ptlist)); remove all same point from list
          ;; will not remove if not exactly meeting; some may remain in list,
          ;; which is why above checks whether already a Block there
      ); while
    ); progn
  ); if
  (prin1)
)
Kent Cooper, AIA
0 Likes
Message 8 of 32

Dan-Rod
Advocate
Advocate
now that it is not a block, is it possible to modify so that the letter is a prefix? and that in the end it sends to a .csv file? only with the list of texts?
0 Likes
Message 9 of 32

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

....

Here's a quick one to place text that denotes how many common points are found.


Maybe you didn't notice the two black Circles [really black, not index color 7 white/black, but TrueColor 0,0,0] that are part of the Blocks.  I assume if it's done with Text, it should also draw those Circles.  @Dan-Rod would need to say whether that would suffice, rather than having actual Block insertions.

 

EDIT:  It also "violates" the original description, and Message 5 elaboration, involving 4 or more always getting the 4R Block, no matter how many Lines meet there.

Kent Cooper, AIA
0 Likes
Message 10 of 32

ronjonp
Advisor
Advisor

@Dan-Rod wrote:
now that it is not a block, is it possible to modify so that the letter is a prefix? ..

Change this: 

(cons 1 (strcat (itoa i) "R"))

to this:

(cons 1 (strcat "R" (itoa i)))

 

0 Likes
Message 11 of 32

ronjonp
Advisor
Advisor

@Kent1Cooper 

I did notice the faint circles on my screen but since the insertions points of the blocks are in the middle of nowhere, I decided to use text as a quick example. Plus it will work with an infinite number of common points. 🙂

ronjonp_0-1680546948875.png

 

 

0 Likes
Message 12 of 32

Dan-Rod
Advocate
Advocate

adds the blocks but stops, only inserts 2 blocks (at the points where they appear in example 2), apparently there is an error, I attach file with correct scale and block center at 0,0,0

 

 

DanRod_1-1680547181496.png

 

DanRod_0-1680546945567.png

 

0 Likes
Message 13 of 32

Kent1Cooper
Consultant
Consultant

Nothing attached.  It worked for me in the original drawing.  Is this one different [for example, Polylines instead of some of the Lines]?

Kent Cooper, AIA
0 Likes
Message 14 of 32

ronjonp
Advisor
Advisor

@Dan-RodIf you're stuck on using a block, maybe create an attribute then fill it in with the correct number.

0 Likes
Message 15 of 32

Dan-Rod
Advocate
Advocate

I appreciate the support, the two answers are going towards the objective, just check in the case of @ronjonp that the limit is 4, there are no tools with more than 4 outputs, and if it is possible to extract in .csv.

In the case of @Kent1Cooper, it also inserts the blocks mentioned in the original file, it only stopped after inserting 2, fix the detail of the scale and the origin point of the block, I hope I can run it completely, also see if it is possible to extract the list of the blocks inserted in .csv

0 Likes
Message 16 of 32

Dan-Rod
Advocate
Advocate

sorry

 

0 Likes
Message 17 of 32

Kent1Cooper
Consultant
Consultant
Accepted solution

The failure is because there is no 4R Block defined in the new drawing.  EDIT:  Try mine [attached].

Kent Cooper, AIA
0 Likes
Message 18 of 32

Dan-Rod
Advocate
Advocate
Of course, I'm starting with custom files to automate processes, all your comments are welcome and I'll take them into account
0 Likes
Message 19 of 32

ronjonp
Advisor
Advisor
Accepted solution

@Dan-Rod 

This will only place your 3's and 4's and does not require blocks to be defined.

 

(defun c:foo (/ a b i m p r s)
  (cond	((setq s (ssget '((0 . "LINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq r (cons (list (vlax-curve-getstartpoint e) (vlax-curve-getendpoint e)) r))
	 )
	 (setq r (apply 'append r))
	 (mapcar 'set '(a b) '(0 0))
	 (while	(setq p (car r))
	   (setq r (cdr r))
	   (setq m (vl-remove-if-not '(lambda (x) (equal p x 1e-4)) r))
	   (if (> (setq i (1+ (length m))) 2)
	     (progn (if	(= 3 i)
		      (setq a (1+ a))
		      (setq b (1+ b))
		    )
		    (entmake (list '(0 . "TEXT")
				   '(100 . "AcDbEntity")
				   '(67 . 0)
				   '(8 . "Junction_Label")
				   '(100 . "AcDbText")
				   (cons 10 p)
				   '(40 . 7.5)
				   (cons 1
					 (strcat (if (= 3 i)
						   "3"
						   "4"
						 )
						 "R"
					 )
				   )
				   '(50 . 0.)
				   '(41 . 1.)
				   '(51 . 0.)
				   '(71 . 0)
				   '(72 . 1)
				   (cons 11 p)
				   '(100 . "AcDbText")
				   '(73 . 2)
			     )
		    )
	     )
	   )
	   (foreach x m (setq r (vl-remove x r)))
	 )
	 (alert (strcat "\n" (itoa a) " - 3's & " (itoa b) " - 4's"))
	)
  )
  (princ)
)

 

0 Likes
Message 20 of 32

Dan-Rod
Advocate
Advocate

it works, is it possible that at the end it will extract a .csv with the final list of all the texts that were inserted?

0 Likes