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

Divide with blocks and keep attributes?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
mid-awe
483 Views, 10 Replies

Divide with blocks and keep attributes?

Hi all,

 

I need a function that will allow me to do a "divide" with blocks but I need the single attribute to remain intact. Does anyone here know of anything like that? 

 

I need the blocks to align with object and keep the attribute. I did get it to work with constants but the function that I need to run next failed because of the constant. My variable is preset and locked.

 

Thank you.

10 REPLIES 10
Message 2 of 11
Hallex
in reply to: mid-awe

Here is a quick example, try to adopt them to your nrrds,

change block name, scale etc:

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


(defun c:DVB  (/ acsp div dpar en epar gettangent leg obj pt pure spar step)
  (vl-load-com)
  ;; written by VovKa

(defun gettangent (curve pt)
  
	 (setq param (vlax-curve-getparamatpoint curve pt)
	       ang ((lambda (deriv)
		   (if (zerop (cadr deriv))
		     (/ pi 2)
		     (atan (apply '/ deriv))
		   )
		 )
		  (cdr (reverse
			 (vlax-curve-getfirstderiv curve param)
		       )
		  )
		)
)
  ang
  )
  
  ;;			main part			;;
  
  (setq acsp
	 (vla-get-block
	   (vla-get-activelayout
	   (vla-get-activedocument
	     (vlax-get-acad-object)))))

  (if (and (setq en (entsel "\nSelect pline: "))
    (setq step (getreal "\nStep distance: ")))
    (progn
    
        (setq obj (vlax-ename->vla-object (car en))
        leg (vlax-curve-getDistAtParam obj( vlax-curve-getEndParam obj))
        div (fix (/ leg step))
	      pure (* div step))
      (setq spar (vlax-curve-getstartparam obj)
	    dpar (- (vlax-curve-getparamatdist obj step) spar)
	    epar (vlax-curve-getendparam obj))
      (while (< spar epar)
	(setq pt (vlax-curve-getclosestpointto obj
		   (vlax-curve-getpointatparam obj spar)))
	(vl-catch-all-apply 'vla-insertblock (list acsp (vlax-3d-point pt) "MyBlockName" 1 1 1 (gettangent obj pt)))
	(setq spar (+ spar dpar)))))
  (princ)
      )
;;-----------------------------------------------------------------------;;

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 11
Alfred.NESWADBA
in reply to: mid-awe

Hi,

 

>> I need a function that will allow me to do a "divide" with blocks but I need the single attribute to remain intact

Just to make sure, what version of AutoCAD do you have? Because since AutoCAD 2012 you have the associative array also for objects along paths, see command _ARRAYPATH (>>>details<<<).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 4 of 11
devitg
in reply to: mid-awe

as the attribute a  constant value? 

Could you upload a sample dwg ?

Message 5 of 11
mid-awe
in reply to: Alfred.NESWADBA

Thank you for that. I'm on 2013 but all the other machines that I must support are 2012. I did not know ARRAYPATH, That's worth a try. 

 

The thing is my block  is set off of 0,0 so that is stands away from the polyline, but in the center of the block is a single attribute that I need to rotate to 0deg. Once the attribute was dropped I could not re-add it but also when I set the attribute to constant it would appear but was not able to be rotated. I'll give ARRAYPATH a try first thing in the morning. Thank you again.

Message 6 of 11
mid-awe
in reply to: Hallex

Looks interesting, I need to see how it works in my situation. Thank you, I can't wait to give it a try.

Message 7 of 11
mid-awe
in reply to: devitg

Yeah I can, but I don't want the constant; it was the only way I was able to keep the attribute in the function, but it was not able to be aligned to 0 so it's no good.

Message 8 of 11
devitg
in reply to: mid-awe

A sample DWG , worth 10000000000000000 words .

Please upload it 

 

 

Message 9 of 11
mid-awe
in reply to: Alfred.NESWADBA

Arraypath is interesting and I'll keep it in mind for future projects, but in this case it does not work. A few reasons. I will need the path divided by specific numbers and array path works more like the measure command. I could get the length and user input, do the math, and then automate the command, but it still wouldn't work because of other step I need. I need the block to align. The arraypath for whatever reason is placing the block far outside and not keeping the insert point on the path like divide does. 

 

It was worth a try, I always prefer built-in functions first. Thank you.

Message 10 of 11
mid-awe
in reply to: Hallex

Thank you, very nice function, but also fails to do as I need. I'll look more deeply into it since it seems to work nicely for what it does, but it forces the block to stand upright, which unfortunately will not always be the case for my needs, that is why I rotate the attribute instead of the entire block.

 

Thank you, there is some nice vl use in that function and I'm sure I'll learn alot studying it.

Message 11 of 11
mid-awe
in reply to: mid-awe

Ok, I worked out a solution. It's far from ideal but it works.

 

I created a custom TIC for this application and after the "divide" command runs, I use "acet-block-replace" to swap out the TIC for my block which then requires "attsync" before my attributes are visible. Then I can run my AttAlign function to rotate the attributes in a repeat loop until they are all set the way I need them to be.

 

Anyway, thank you all for your help. It's good to see this forum still banding together. Smiley Very Happy

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

Post to forums  

Autodesk Design & Make Report

”Boost