See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Lisp required to Align Blocks attritubes to its Block angle.

  1. #1
    Member
    Join Date
    2016-09
    Posts
    8
    Login to Give a bone
    0

    Default Lisp required to Align Blocks attritubes to its Block angle.

    Hi Friends,
    i have a task to align attributes as per the selected block angles, Actually i have a lisp that aligns as per the block angle,
    but there is some mess in line spacing between the texts, so could someone please help me to fix this issue.

    attaching screenshots & Existing lisp for more understanding.

    Thanks in Advance.

    HTML Code:
    ; pick 3 texts and align to a block
    (vl-load-com)
    (defun c:tritxt ( / oldang oldunit oldsnap obj ang ins Tp xscale bname ins)
    (setq oldang (getvar 'angdir))
    (setq oldunit (getvar 'aunits))
    (setq oldsnap (getvar 'osmode))
    (setvar 'angdir 0)
    (setvar 'aunits 3)
    (setvar 'osmode 0)
    
    (setq obj (vlax-ename->vla-object (car (entsel "\nPick Block object"))))
    (setq Objname (vla-get-Objectname obj))
    (if (/= Objname "AcDbBlockReference") ; check is it a block
    (alert "You have not Picked a block\n\nPress ok ")
    (progn
    (setq ang (vla-get-rotation obj))
    (setq ins (vlax-safearray->list (vlax-variant-value(vla-get-insertionpoint 
    
    obj))))
    (setq xscale (vla-get-XScaleFactor obj))
    (setq bname (vla-get-name obj))
    
    (cond
    ((if (= bname "TERM_AER_E")(setq len 10))) ; as per sample 
    ((if (= bname "xxxx")(setq len 10))) ; other blocks change len value
    )tri
    (setq off 8.0)
    
    (setq Tp  (vlax-ename->vla-object (car  (entsel "\nPick text1"))))
    (setq pt1 (vlax-3d-point  (polar ins (+ ang (/ pi 0.5)) off)))
    (vla-put-insertionpoint Tp  pt1)
    (vla-put-rotation Tp ang )
    
    (setq Tp  (vlax-ename->vla-object (car  (entsel "\nPick text2"))))
    (setq pt1 (vlax-3d-point  (polar ins (+ ang (/ pi 0.5)) off)))
    (vla-put-insertionpoint Tp  pt1)
    (vla-put-rotation Tp ang )
    
    
    (setq Tp  (vlax-ename->vla-object (car  (entsel "\nPick text3"))))
    (setq pt1 (vlax-3d-point  (polar ins (+ ang (/ pi 0.5)) off)))
    (vla-put-insertionpoint Tp  pt1)
    (vla-put-rotation Tp ang )
    
    (setvar 'angdir oldang)
    (setvar 'aunits oldunit)
    (setvar 'osmode oldsnap)
    )
    )
    )[ATTACH=CONFIG]108346[/ATTACH]
    Note: Already posted the same in cadtutor, but no luck for me there

  2. #2
    Member
    Join Date
    2016-09
    Posts
    8
    Login to Give a bone
    0

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.

    missed to do atachments
    Last edited by malikbasha1308735440; 2020-08-12 at 10:33 PM.

  3. #3
    Active Member
    Join Date
    2015-12
    Location
    Western Europe
    Posts
    57
    Login to Give a bone
    1

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.

    I cannot open your drawing as it is in a later version of AutoCAD than mine. Please resend saved as AutoCAD2012 or earlier.

  4. #4
    Member
    Join Date
    2016-09
    Posts
    8
    Login to Give a bone
    0

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.

    Hi dlanor,
    thank you so much for looking my post
    i resolved it myself by the following edit in code

    ; pick 3 texts and align to a block
    (vl-load-com)
    (defun c:test ( / oldang oldunit oldsnap obj ang ins Tp xscale bname ins)
    (setq oldang (getvar 'angdir))
    (setq oldunit (getvar 'aunits))
    (setq oldsnap (getvar 'osmode))
    (setvar 'angdir 0)
    (setvar 'aunits 3)
    (setvar 'osmode 0)

    (setq obj (vlax-ename->vla-object (car (entsel "\nPick Block object"))))
    (setq Objname (vla-get-Objectname obj))
    (if (/= Objname "AcDbBlockReference") ; check is it a block
    (alert "You have not Picked a block\n\nPress ok ")
    (progn
    (setq ang (vla-get-rotation obj))
    (setq ins (vlax-safearray->list (vlax-variant-value(vla-get-insertionpoint

    obj))))
    (setq xscale (vla-get-XScaleFactor obj))
    (setq bname (vla-get-name obj))

    (cond
    ((if (= bname "TERMINAL")(setq len 4.5))) ; as per sample
    ((if (= bname "xxxx")(setq len 5))) ; other blocks change len value
    )
    (setq off 6.0)
    (setq off1 8.0)

    (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text1"))))
    (setq pt1 (vlax-3d-point (polar ins (+ ang (/ 0.25)) off1)))
    (vla-put-insertionpoint Tp pt1)
    (vla-put-rotation Tp ang )

    (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text2"))))
    (setq pt1 (vlax-3d-point (polar ins (+ ang (/ 0.2)) off1)))
    (vla-put-insertionpoint Tp pt1)
    (vla-put-rotation Tp ang )

    (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text3"))))
    (setq pt1 (vlax-3d-point (polar ins ang (* len 1.7))))
    (vla-put-insertionpoint Tp pt1)
    (vla-put-rotation Tp ang )

    (setvar 'angdir oldang)
    (setvar 'aunits oldunit)
    (setvar 'osmode oldsnap)
    )
    )
    )
    - - - Updated - - -

    @dlanor could you guide me on how to edit the posted thread

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    1

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.

    I think you will need to determine first is the height of all three elements you wish to align with an included buffer between the three elements. Once you have that, you can align them as desired. AutoCAD provides a height for the MText objects, but that is only the height of the font for each line. Depending on the font, this height is not the actual height of the text.

    To get the actual height of the text or block, you could use the vla-getboundingbox method of the each object. Naturally, this will return the lower left and upper right corners of the object as they are currently displayed. If these elements are rotated, the actual height will be incorrect. You'll then need to rotate the objects back to the horizontal rotation before getting the bounding box extents. These two elements are returned as variants. They will need to be converted back to lists.
    Code:
    (defun op:GetObjectHeight (object / op:SafeList op:VariantValue tmpRotation pntLL pntUR fltHeight)
     ;_ Convert Safearray to list
      (defun op:SafeList (value)
        (if	(= (type value) 'variant)
          (setq value (m:variantvalue value))
        )
        (setq value (vl-catch-all-apply 'vlax-safearray->list (list value)))
        (if	(vl-catch-all-error-p value)
          nil
          value
        )
      )
     ;_ Get value of variant
      (defun op:VariantValue (value)
        (setq value (vl-catch-all-apply 'vlax-variant-value (list value)))
        (if	(vl-catch-all-error-p value)
          nil
          value
        )
      )
      (setq tmpRotation (vla-get-rotation object))
      (vla-put-rotation object 0.0)
      (vla-getboundingbox object 'pntLL 'pntUR)
      (vla-put-rotation object tmpRotation)
      (setq	pntLL	  (op:SafeList pntLL)
    	pntUR	  (op:SafeList pntUR)
    	fltHeight (- (cadr pntUR)
    		     (cadr pntLL)
    		  )
      )
      fltHeight
    )
    We still need to determine the desired buffer. I think the line spacing which can be found in the MText elements would be a good starting point. Line spacing is from a point of the font on one line to the similar point on the next line. Therefore, we probably could reduce the line spacing by the font height to get a buffer.
    Code:
    (defun op:GetMTextBuffer (object / fltBuffer fltHeight fltSpacing)
      (if (= (vla-get-objectname object) "AcDbMText")
        (setq fltHeight  (vla-get-height object)
    	  fltSpacing (vla-get-linespacingdistance object)
    	  fltBuffer (- fltSpacing fltHeight)
        )
      )
      fltBuffer
    )
    Now that we can get the height of objects and also determine an appropriate buffer, we can determine placement. Now let's determine the overall height of the three elements.
    Code:
          (setq Tp1 (vlax-ename->vla-object (car (entsel "\nPick text1"))))
          (setq fltHeight (op:GetObjectHeight Tp1))
          (setq fltBuffer (op:GetMTextBuffer Tp1))
          (setq Tp2 (vlax-ename->vla-object (car (entsel "\nPick text2"))))
          (setq fltHeight (+ fltHeight (op:GetObjectHeight Tp2)))
          (if (not fltBuffer)
    	(setq fltBuffer (op:GetMTextBuffer Tp2))
          )
          (setq Tp3 (vlax-ename->vla-object (car (entsel "\nPick text3"))))
          (setq fltHeight (+ fltHeight (op:GetObjectHeight Tp3)))
          (if (not fltBuffer)
    	(setq fltBuffer (op:GetMTextBuffer Tp3))
          )
          (setq fltHeight (+ fltHeight (* fltBuffer 2.0)))
    In your original code, you have specified the offset from the initial block selection and to use it's rotation angle. Instead of adjusting each text element at each selection, let's determine the placement for each first.
    Code:
          (setq pt	(polar ins (+ ang (/ pi 0.5)) off)
    	    pt1	(polar pt
    		       (+ ang (* pi 0.5))
    		       (- (/ fltHeight 2.0) (op:GetObjectHeight Tp1))
    		)
    	    pt2	(polar pt1 (- ang (* pi 0.5)) fltBuffer)
    	    pt3	(polar pt
    		       (- ang (* pi 0.5))
    		       (- (/ fltHeight 2.0) (op:GetObjectHeight Tp3))
    		)
          )
    Once those placements are determined, we can adjust the elements. Since we are doing the same thing on different elements, we should make a subroutine to reduce the repetitive code.
    Code:
    (defun op:AdjustObject (object insertion rotation)
      (vla-put-insertionpoint object (vlax-3d-point insertion))
      (vla-put-rotation object rotation)
    )
    With the AdjustObject subroutine, we can now adjust the three elements to the desired placement and rotation.
    Code:
          (op:AdjustObject Tp1 pt1 ang)
          (op:AdjustObject Tp2 pt2 ang)
          (op:AdjustObject Tp3 pt3 ang)
    All of this code should replace the lines in your original code between the offset designation and restoring system variables.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.

    To edit your posts, there should be an Edit Post button at the bottom right of each of your posts.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  7. #7
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Lisp required to Align Blocks attritubes to its Block angle.


Similar Threads

  1. Need a help in modification of lisp. Please update the lisp code as required.
    By brahmanandam.thadikonda762224 in forum AutoLISP
    Replies: 0
    Last Post: 2018-09-20, 04:12 AM
  2. Replies: 0
    Last Post: 2018-01-19, 03:31 AM
  3. Replies: 0
    Last Post: 2010-09-21, 03:45 PM
  4. Should Revit align its coordinate system with AutoCAD WCS 0,0?
    By Wes Macaulay in forum Revit Architecture - General
    Replies: 33
    Last Post: 2009-03-03, 06:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •