Connecting dynamic block with Autolisp or .net

Connecting dynamic block with Autolisp or .net

abee123456789
Participant Participant
2,128 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,129 Views
25 Replies
Replies (25)
Message 21 of 26

abee123456789
Participant
Participant

No, not really. Its a rare occasion that there is.

0 Likes
Message 22 of 26

abee123456789
Participant
Participant

This works good. Any recommendations on learning lisp? I would like to learn how to tweak it in other scenarios.

0 Likes
Message 23 of 26

abee123456789
Participant
Participant

Thank you i appreciate the help. Do you have any recommendation on learning lisp?

0 Likes
Message 24 of 26

pbejse
Mentor
Mentor

@abee123456789 wrote:

Thank you i appreciate the help. Do you have any recommendation on learning lisp?


AfraLISP - Learn AutoLISP for AutoCAD productivity  <--- That's where i started 

 

0 Likes
Message 25 of 26

Sea-Haven
Mentor
Mentor

Still think can be done without dynamic blocks using a donut as block, entering length parameter a len of 0 means go from end point.

 

Note dwg has an error 1' length of 1" is overlapped with 4' of 3/4.

 

I wrote something ages ago L1 is go left 1 unit, u1 up 1 unit and so on.

0 Likes
Message 26 of 26

pbejse
Mentor
Mentor
Accepted solution

@abee123456789 wrote:

Thank you i appreciate the help. Do you have any recommendation on learning lisp?


 

Here's the completed code Step 2 & 3

 

(defun c:Connected (/  _DynPop lbd ci lbp lb_IP np i civ chp npc ci_ip inter_P interLst)
(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"))
  )
;;;  
(defun _remdup (l)
  (if (car l)
    (cons (car l) (_remdup (vl-remove-if '(lambda (v)
					 (equal (car l) v 0.1)) (cdr l))))
  )
)

(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))
		  	(setq interLst (cons inter_P interLst))
			)
		)
	  )
	  (and interLst
		(setq interLst (_remdup interLst)
		      interLst (mapcar '(lambda (d)
					  (list (distance lb_IP d) d)) interLst))
		(setq interLst (mapcar 'cadr (vl-sort interLst '(lambda (a b)(< (car a)(car b)))))
		      lbp (cadadr lbp))
		(not (vlax-put lbp 'Value (distance lb_IP (Car interLst))))
	        (setq interLst (append interLst (list np)))
	        (while (and (setq a (Car interLst) interLst (cdr interLst)))
	        	(vlax-invoke 
				   (setq lbd (vla-copy lbd)) 'Move lb_IP (setq lb_IP a))
		 (setq lbp (_DynPop lbd ) lbp (cadadr lbp))
		 (vlax-put lbp 'Value (distance lb_IP (Car interLst)))
		 	)	
	  )
	)
    )
  (princ)
  )

 

HTH

0 Likes