Author Topic: Vla-Put-textstring on IAxDbDocument  (Read 3198 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Vla-Put-textstring on IAxDbDocument
« on: October 29, 2016, 08:22:47 AM »
If I use ALE_Block_PutStringOnAttributes on a IAxDbDocument Interface (ODBX document) there are some problem for the attributes that are other than left justified.
If the InsertionPoint is different than the TextAlignmentPoint, the process puts them in coincidence, visually shifting the position of the attribute.
If I open the file and move or copy the block all goes ok... Workaround?
Code: [Select]
(defun ALE_Block_PutStringOnAttributes (VlaObj ValLst / AttLst TmpLst VlaDoc SstPrp TxtObj AlgTyp ObjClr FthClr TxtVal
                                                        TxtOri LenOri LenVal)
  (setq
    AttLst (ALE_Block_GetAttributes VlaObj)                             
    VlaDoc (vla-get-Document VlaObj)                  ; un IAxDbDocument non ha questa proprietà a
    SstPrp (vlax-property-available-p VlaDoc 'SelectionSets); differenza di IAcadDocument: An AutoCAD drawing
    FthClr (vla-get-Color (ALE_Utl_GetItem (vla-get-Layers VlaDoc) (vla-Get-Layer VlaObj)))
  )
  (foreach ForElm ValLst
    (if (setq TmpLst (assoc (strcase (car ForElm)) AttLst))
      (progn
        (or (setq TxtVal (cdr ForElm)) (setq TxtVal ""))
        (setq TxtOri (vla-Get-textstring (setq TxtObj (cadddr TmpLst))))
        (vla-Put-textstring TxtObj TxtVal)
        (or
          SstPrp ; only for IAxDbDocument
          (= acAlignmentLeft (setq AlgTyp (vla-Get-Alignment TxtObj))) ; and /= acAlignmentLeft
          (progn ; try to fix ScaleFactor
            (if (= acAlignmentFit AlgTyp)
              (progn
                (setq LenOri (strlen TxtOri)   LenVal (strlen TxtVal))
                (and (zerop LenOri) (setq LenOri 1)) (and (zerop LenVal) (setq LenVal 1))
                (vla-Put-ScaleFactor TxtObj (/ (* (vla-Get-ScaleFactor TxtObj) (strlen TxtOri)) (strlen TxtVal)))
              ); il testo comunque non viene ottimizzato se il font è proporzionale
            )
            (entmod (entget (vlax-vla-object->ename TxtObj))); per aggiornare la dimensione del testo
          )
        )
        (vla-update TxtObj)
      );progn
    )
  )
  (vla-update VlaObj)
)

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Vla-Put-textstring on IAxDbDocument
« Reply #1 on: October 29, 2016, 09:46:07 AM »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Vla-Put-textstring on IAxDbDocument
« Reply #2 on: October 29, 2016, 09:54:17 AM »
Unfortunately a known bug which was never fixed - see:

https://www.theswamp.org/index.php?topic=51588
https://www.theswamp.org/index.php?topic=30594
Thanks Lee  :-)
I have solved with this version but only in Bricscad (non in AutoCAD???) see   ; 20161029:
Code: [Select]
(defun ALE_Block_PutStringOnAttributes (VlaObj ValLst / AttLst TmpLst SstPrp TxtObj TxtVal InsPtn)
  (setq
    AttLst (ALE_Block_GetAttributes VlaObj)                                    ; un IAxDbDocument non ha questa proprietà a                             
    SstPrp (vlax-property-available-p (vla-get-Document VlaObj) 'SelectionSets); differenza di IAcadDocument: An AutoCAD drawing
  )
  (foreach ForElm ValLst
    (if (setq TmpLst (assoc (strcase (car ForElm)) AttLst))
      (progn
        (or (setq TxtVal (cdr ForElm)) (setq TxtVal ""))
        (setq
          TxtObj (cadddr TmpLst)
          InsPtn (vla-Get-InsertionPoint TxtObj)
        )
        (vla-Put-textstring TxtObj TxtVal); 20161029
        (or
          SstPrp
          (= acAlignmentLeft (vla-Get-Alignment TxtObj))
          (vla-Put-InsertionPoint TxtObj InsPtn); 20161029
        )
        (vla-update TxtObj)
      )
    )
  )
  (vla-update VlaObj)
)
Thanks again for your links, I have not found in my previous search.
 :-)

Edit: better test on Bricscad, the problem does not even exist without "; 20161029" lines...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Vla-Put-textstring on IAxDbDocument
« Reply #3 on: November 06, 2016, 03:42:36 AM »
I noticed today that the same problem (in AutoCAD) exists even if you export the block with the command WBlock.  :knuppel2: