Connecting dynamic block with Autolisp or .net

Connecting dynamic block with Autolisp or .net

abee123456789
Participant Participant
2,119 Views
25 Replies
Message 1 of 26

Connecting dynamic block with Autolisp or .net

abee123456789
Participant
Participant

Hello,

 

I am new to autolisp, and .net and looking for a little guidance in the right direction.

 

I have created two dynamic blocks a circle and a line. I have attached them.

I want to connect the circle block perpendicular to the line block.

 

and then split the line block where every the circle block connects to perpendicularly

I labeled them from step 1 being the beginning stage and step 3 being the final stage.

 

Any help will be appreciated.

 

Thank you,

 

0 Likes
Accepted solutions (1)
2,120 Views
25 Replies
Replies (25)
Message 2 of 26

Sea-Haven
Mentor
Mentor

A alternative approach may be easier than trying to do with dynamic blocks. There is various similar pattern joins out there. 

 

Select circle blocks then line, a connect line is drawn and a question asked fillet yes no, would this be useful ?

0 Likes
Message 3 of 26

abee123456789
Participant
Participant

Not really, we used this blocks for all our drawings. I was just wonder if theres a macro or something that can do step 2 at least. Any ideas?

0 Likes
Message 4 of 26

Sea-Haven
Mentor
Mentor

Why not just make a new single dynamic block the correct shape ? You could have a dcl that asks for all the lengths etc. 3 vertical 3 horizontal and auto adjusts the block. Same with size 3/4. distance 1, distance 2 etc. Pretty sure You can link end of lines to a another end. I dont do much dynamic blocks some one may link yours. Can do front end then.

 

That would be my approach, how many patterns are involved ?

 

0 Likes
Message 5 of 26

abee123456789
Participant
Participant

Would that remove the dimensions?

0 Likes
Message 6 of 26

Sea-Haven
Mentor
Mentor

No, I dont do much with dynamic blocks but you should be able to link the objects using the stretch option. Hopefully some one will jump in redoing the block. 

 

SeaHaven_0-1645750935487.png

 

As I said earlier how many patterns? 

 

 

0 Likes
Message 7 of 26

abee123456789
Participant
Participant

There many patterns. Is there way to use the grip of the circle block to meet the line block perpendicular to it 

Message 8 of 26

Sea-Haven
Mentor
Mentor

What I was saying is rethink the whole pattern making. Enter a length draw line, add circle with a entered offset and size repeat as required, the offset is a simple -ve for left. This would be fast I use a dynamic dcl for this type of thing so it remembers the last entered values so may change only 1 value like length for repeated sides.

 

SeaHaven_0-1645754189923.png

 

Ps use Donut for filled circle.

 

 

0 Likes
Message 9 of 26

pbejse
Mentor
Mentor

@abee123456789 wrote:

..I want to connect the circle block perpendicular to the line block.


I guess that can be done, tell us, is the attached drawing sample is just an example? or those blocks are the actual blocks you are going to use?

 

Writing a program that deals with Dynamic blocks will always have issues, especially with parameter names.

But this is certainly doable.

 

Also, please show more scenarios.

 

0 Likes
Message 10 of 26

abee123456789
Participant
Participant

The drawing is just an example. There could be 100 of circle blocks going different direction but I want to click a button or something that will be perpendicular to the line. 

0 Likes
Message 11 of 26

pbejse
Mentor
Mentor

@abee123456789 wrote:

The drawing is just an example. There could be 100 of circle blocks going different direction but I want to click a button or something that will be perpendicular to the line. 


I figured as much.  The "line"  are of different angles not just Hor and Vert? if Yes show us please.

"Circle" block rotation is always 0? [ in relation to "Ängle1" parameter's value ]

 

Is there a direction for the "Line" block? This is important when placing these on the intersection point

 

The "Line" and "Circle"block is the actual block you're going to use YES? 

 

0 Likes
Message 12 of 26

abee123456789
Participant
Participant

The circle block will be rotating in 90 degree increments 

0 Likes
Message 13 of 26

ВeekeeCZ
Consultant
Consultant

Step 2 done.

 

(vl-load-com)
(defun c:Step2 ( / LM:setdynprops s p1 p2 a p x)
 
  ;; Set Dynamic Block Properties  -  Lee Mac ; http://www.lee-mac.com/dynamicblockfunctions.html#setdynamicprops
;; lst - [lst] Association list of (( . ) ... )

(defun LM:setdynprops ( blk lst / itm )
    (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst))
    (foreach x (vlax-invoke blk 'getdynamicblockproperties)
        (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
            (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))))))

  ; ---------------------------------------------------------------------------------------

  (if (and (setq s (ssget "_:L" '((0 . "INSERT"))))
	   (setq p1 (getpoint "\nSpecify first point of vector: "))
	   (setq p2 (getpoint p1 "\nSpecify second point of vector: "))
	   (setq a (+ (/ pi 2) (angle p1 p2)))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (setq p (cdr (assoc 10 (entget e))))
      (setq x (inters p1 p2 p (polar p a 1) nil))
      (LM:setdynprops (vlax-ename->vla-object e) (list (cons "Distance1" (distance p x))
						       (cons "Angle1" (angle p x))))))
  (princ)
  )
 

 

Message 14 of 26

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Step 2 done.


I also had step 2 at the ready @ВeekeeCZ 😉

I'm waiting on confirmation on other stuff like "rotation" and the lik

 

 

(defun c:Connected (/  _DynPop lbd ci lbp lb_IP np i civ chp npc ci_ip inter_P)
(defun _DynPop (o / data)
  (setq data (mapcar '(lambda (dp)
	     (list (vla-get-PropertyName dp)(vlax-get dp 'Value) dp))
		    (vlax-invoke o 'GetDynamicBlockProperties))
	)
  (mapcar '(lambda (v) (cdr (assoc v data))) '("Angle1" "Distance1"))
  )
(print "\nSelect Line Block")
  (if (and
	(setq lbd (ssget "_+.:S:E:L" '((0 . "INSERT")(2 . "LINE,`*U*"))))
	(princ "\nSelect Circle Block(s)")
	(setq ci (ssget "_:L" '((0 . "INSERT")(2 . "Circle,`*U*"))))
    	(eq "LINE" (strcase (vla-get-EffectiveName
			      (setq lbd (vlax-ename->vla-object (ssname lbd 0))))))
	(minusp (vlax-get lbd 'IsDynamicBlock))
	)
    (progn
      (setq lbp (_DynPop lbd )
	    lb_IP (vlax-get lbd 'InsertionPoint)
	    np ( polar lb_IP (Caar lbp)(caadr lbp))
	    an (+ (/ pi 2) (angle lb_IP np)))
      
	(repeat (setq i (sslength ci))
	  	(setq civ (vlax-ename->vla-object (ssname ci (setq i (1- i)))))	  	
	  (and
	    	(eq "CIRCLE" (strcase (vla-get-EffectiveName civ)))
	  	(setq cbp (_DynPop civ ))
	        (setq npc
		       (polar (setq ci_ip (vlax-get civ 'InsertionPoint))
			      an
			      (caadr cbp)
		       )
		)
		(setq inter_P ( inters  lb_IP np ci_ip npc nil))
		(progn
			(vlax-put (cadar cbp) 'Value (angle ci_ip inter_P))
			(vlax-put (cadadr cbp) 'Value (distance ci_ip inter_P))
		)
		)
	  )
	)
    )
  (princ)
  )

 

 

 

Message 15 of 26

abee123456789
Participant
Participant

Nice, I am pretty new to this what language is that and how do I start the process?

 

Thank you 

0 Likes
Message 16 of 26

abee123456789
Participant
Participant

Is this possible using C# that is what ive been working with and I am fairly new. 

0 Likes
Message 17 of 26

pbejse
Mentor
Mentor

@abee123456789 wrote:

Nice, I am pretty new to this what language is that and how do I start the process?

 


Depending on the condition of the drawing, the program may not work as expected. The code I posted relies heavily on the current  Ängle1 Paramater value. So its more extending the end to the line and not always perpendicular, whilst @ВeekeeCZ offering will be perpendicular as you requested. But both will fail if the "circle" Block rotaion is other than 0

 

That is why I'm asking for a real scenario so we can make the proper adjustment to the code.

 


@abee123456789 wrote:

Is this possible using C# that is what ive been working with and I am fairly new. 


I usually use C# for sheet set processing , mostly data get/set data [ attributes / Xref /Layer infor ...]

For geometric manipulation, i stick with AutoLisp/Visual lisp.

 

I suggest you post your request here <-- Autocad .Net

 

HTH

 

0 Likes
Message 18 of 26

ВeekeeCZ
Consultant
Consultant

Step 3

 

(vl-load-com)

(defun c:Step3 ( / LM:setdynprops LM:getdynpropvalue :getpoints e p1 p2 ps s i)
  
  ;; Set Dynamic Block Properties  -  Lee Mac ; http://www.lee-mac.com/dynamicblockfunctions.html#setdynamicprops
  ;; lst - [lst] Association list of (( . ) ... )
  (defun LM:setdynprops ( blk lst / itm )
    (setq lst (mapcar '(lambda ( x ) (cons (strcase (car x)) (cdr x))) lst))
    (foreach x (vlax-invoke blk 'getdynamicblockproperties)
      (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
	(vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))))))
  
  ;; Get Dynamic Block Property Value  -  Lee Mac ; http://www.lee-mac.com/dynamicblockfunctions.html#setdynamicprops
  (defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
	     (vlax-invoke blk 'getdynamicblockproperties)))
  
  (defun :getpoints (e / o d p1 p2)
    (if (and  (setq o (vlax-ename->vla-object e))
	      (setq a (LM:getdynpropvalue o "Angle1"))
	      (setq d (LM:getdynpropvalue o "Distance1"))
	      (setq p1 (cdr (assoc 10 (entget e))))
	      (setq p2 (polar p1 a d))
	      )
      (list p1 p2)))
  
  ; -----------------------------------------------------------------------------------------------------------------------
  
  (if (and (setq e (car (entsel "\nSelect block to split: ")))
	   (mapcar 'set '(p1 p2) (:getpoints e))
	   (setq ps (cons p2 ps))
	   (princ "\Select connections (blocks), ")
	   (setq s (ssget "_:L" '((0 . "INSERT"))))
	   (progn (setq s (ssdel e s)) T)
	   )
    (progn
      (repeat (setq i (sslength s))
	(setq ps (cons (cadr (:getpoints (ssname s (setq i (1- i))))) ps)))
      (setq ps (vl-sort ps '(lambda (r1 r2) (< (distance p1 r1) (distance p1 r2)))))
      (LM:setdynprops (vlax-ename->vla-object e) (list (cons "Distance1" (distance p1 (car ps)))
						       (cons "Angle1" (angle p1 (car ps)))))
      (repeat (1- (length ps))
	(command "_.copy" e "" "_non" p1 "_non" (car ps))
	(LM:setdynprops (vlax-ename->vla-object (entlast)) (list (cons "Distance1" (distance (car ps) (cadr ps)))
								 (cons "Angle1" (angle (car ps) (cadr ps)))))
	(setq ps (cdr ps)))))
  (princ)
  )

 

HERE 's a tutorial of how to use LISP.

Good luck.

Message 19 of 26

abee123456789
Participant
Participant

Attached i created a different scenario. Once again is this possible in C# .net That is what ive been missing around with lately. since i read some where that autodesk is going to discontinue lisp support.  

0 Likes
Message 20 of 26

pbejse
Mentor
Mentor

@abee123456789 wrote:

Attached i created a different scenario. Once again is this possible in C# .net That is what ive been missing around with lately. since i read some where that autodesk is going to discontinue lisp support.  


Thank you for posting more samples. We will have a look see.

I replied to that at post # 17, Also, they've been saying that for years and yet it's still here 😊

 

Based on your latest sample, Are there no odd angles at all? 


EDIT: Modified the code at post # 14 for perpendicular mode instead of Extend

0 Likes