Jump to content

Attribute alignment automatically as per standard.


acad1985

Recommended Posts

Hello Everyone,

In my drawing file, there is lot of attributes to Align as per standard. (Attribute are in Block Reference).

It will take lots of time to do with Manual.

All the attribute are in middle of the polyline. I want to align automatically through lisp.

So that when run the command, ATT1 should move and aligned to Starting point of Poly line,

and ATT2 should move and aligned to End point of Poly line (Please see the attached .dwg file)

 

Sample.dwg

 

Please help me anyone to do with lisp.

 

Thanks in Advance.

Link to comment
Share on other sites

Maybe you have posted the wrong dwg? There are no block references with attributes, instead there are attribute definitions and none of these is aligned with the end point of a polyline. Furthermore Case 1 and Case 3 seem to be exactly the same and yet the desired result is different?

 

EDIT: You may also want to look at the case where the Case 1 polyline runs from top right to bottom left.

Edited by Roy_043
Link to comment
Share on other sites

Hi Roy,

Maybe you have posted the wrong dwg?

Yes, I have uploaded Wrong DWG.

Please look at this updated one.

Sample.dwg

Furthermore Case 1 and Case 3 seem to be exactly the same and yet the desired result is different?

Actually i need to align three different cases as per space available in Drawing.

 

Thanks

Edited by acad1985
Link to comment
Share on other sites

Can be done pick pline line arc spline etc near what you want as start pt so att1 goes to this end. Then window the atts. Result is drawn. The reason for picking is if you just use startpoint, endpoint it may draw the atts on wrong ends. Line drawn to right v's to left.

 

 

Needs a few simple defuns, I am sure someone will post, I need to find the group of defuns and have to do real work now. A start http://www.cadtutor.net/forum/showthread.php?104805-Measure-with-Flip-Option

Link to comment
Share on other sites

HI Bigal,

Sorry for the Delay.

Actually I didn't understand what you said, and also i'm not a expert in Lisp. Could you please Help me on this.

 

 

Thanks

Link to comment
Share on other sites

Sorry been busy lately no spare time, will see if I can find time tonight, some else can jump in.

 

Part 2 now having a play a couple of problems like the block attribute is at an odd angle does not help automating.

 

Please where are the att1 & att2 values are coming from I have ignored picking ex blocks rather insert them at correct location when creating. testing lines plines and arcs.

Edited by BIGAL
Link to comment
Share on other sites

Here is something to look at, it needs a fair bit of work, still I corrected the blocks angle so it worked properly and removed the need for extra coding, it needs the text position to be played with and a check for readability. I still dont see the need to insert the blocks 1st rather than adding at ends.

 

(defun stend ( / d1 d2 temp)
(setq stpt   (vlax-curve-getstartPoint Obj)
               endpt  (vlax-curve-getEndPoint Obj)
d1 (distance stpt pt)
               d2 (distance endpt pt)
 )
 (if (> d1 d2)
	(progn 
		(setq temp stpt)
		(setq stpt endpt)
		(setq endpt temp)
	)
)
)


(defun ispline ( /  co-ordsxy I xy co-ords numb len ang1 ang2)
(stend)
(setq co-ords   (vlax-safearray->list     (vlax-variant-value       (vlax-get-property
   obj     "Coordinates"       )    )   )
 )
(setq len (length co-ords))
(setq numb (/ len 2))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
(alert"check direction here")
(setq ang1 (angle (nth 1 co-ordsxy)(nth 0 co-ordsxy)))
(if (= numb 2)
(setq ang2  ang1)
(setq  ang2 (angle (nth (- numb 1) co-ordsxy)(nth  (- numb 2) co-ordsxy)))
)
(command  "-insert" "att1" endpt 1 "" ang1 (rtos (car stpt) 2 2 ))
(command  "-insert" "att2" stpt 1 "" ang2 (rtos (cadr stpt) 2 2 ))
)

(defun isline ( /  ang)
(stend)
(setq ang (angle stpt endpt))
(command  "-insert" "att1" stpt 1 "" ang (rtos (car stpt) 2 2 ))
(command  "-insert" "att2" endpt 1 "" ang (rtos (car stpt) 2 2 ))
)

(defun isarc ( / )
(alert "Non supported item at this time")(exit)
)

(defun iscirc ( / )
(alert "Non supported item at this time")(exit)
)



;;;; starts here
(defun  endptlabel1 ( /  ent)
(setq ent (entsel "pick object near end for start"))
(SETQ ANGBASEE (GETVAR "ANGBASE"))
(SETQ ANGDIRR (GETVAR "ANGDIR"))
(SETQ AUNITSS (GETVAR "AUNITS"))
(SETVAR "ANGBASE" 0.0)
(SETVAR "ANGDIR" 0)
(SETVAR "AUNITS" 3)
(setq    pt (cadr ent))
(setq obj (vlax-ename->vla-object (car ent)))
(setq objname (vla-get-objectname obj))
(setvar 'attdia 0)
(cond
((= objname "AcDbPolyline")(ispline))
((= objname "AcDbLine")(isline))
((= objname "acDbArc")(isarc))
((= objname "AcDbCircle" )(iscircle))
)
(SETVAR "ANGBASE" angbasee)
(SETVAR "ANGDIR" angdirr)
(SETVAR "AUNITS" aunitss)
(princ)
)

(defun  c:aaa ()
(endptlabel1)
)
(defun c:bbb ()
(endptlabel2)
)

Link to comment
Share on other sites

Hello Bigal,

Thank you so much for your Code.

I have tried the code above posted by you. well it's working but, it's update the length on both end.

but i have to move the Attributes to both end from selected place. (Block Attributes already placed in my DWG), so first i have to select the Attributes, and the select the line. after that that selected attributes moved to both end of the line with same rotation angle as line.

 

Thanks again.:)

Link to comment
Share on other sites

I know the text needs some alignment work.

 

But my big question is why are you inserting the blocks then attaching them to the line plines etc I would just add blocks to the objects directly and thats what I have tried to show in the code. This seems to be a 3 step process rather than 1.

 

You can add the pick two blocks at the start and read their attribute value and create new adding to the code

Link to comment
Share on other sites

. But my big question is why are you inserting the blocks then attaching them to the line plines etc I would just add blocks to the objects directly and thats what I have tried to show in the code. This seems to be a 3 step process rather than 1.

 

You can add the pick two blocks at the start and read their attribute value and create new adding to the code

Actually, I'm working on one of the GIS Application,in that the block attributes will be placed automatically center top of the polyline. After that we need to move that block attributes to both end. This will take some time to align manually. That's why I'm asking here, if it's can be done through lisp. That's very helpful to me.

 

 

Thanks

Link to comment
Share on other sites

Not sure why you insert them at centre then want to move them rather than center or end in 1st place. If you make a mistake then yes an extra option, likewise move ends to middle.

Link to comment
Share on other sites

Not sure why you insert them at centre then want to move them rather than center or end in 1st place

 

It's automatically placed on center of the line. we didn't that, in that GIS that blocks always placed on middle of the line.(as per that Program of GIS)

After that we have to align to both end.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...