ActiveX - changing properties bug?

Discussion in 'AutoCAD' started by Bob, Jan 6, 2005.

  1. Bob

    Bob Guest

    I've been trying to get text alignment to change in the drawing after I
    change it with ActiveX (see code below), I decided to try to force the text
    to update by changing the text height to 1 and then back to the height that
    I wanted (20). After I do this the text appears in the drawing as 20 unit
    high but I can not longer select the text object by picking anywhere on the
    text. Only at the insertion point (or anywhere the text at height of 1
    would occupy). And the alignment is still left even though listing the
    object shows it as center. Same result whether I 'update the txtobj or
    'regen the activeviewport.

    What is going on?

    (setq ACADObject (vlax-get-acad-object)
    ACADCollection (vlax-get-property ACADObject 'Documents)
    NewDoc (vlax-invoke-method ACADCollection 'Add)
    CModelSpace (vlax-get-property NewDoc 'ModelSpace)
    LayerCollection (vlax-get-property NewDoc 'Layers)
    testLayer (vlax-invoke-method LayerCollection 'add "testing")
    );setq


    (setq InPt (list 50 50 0)
    TxtHt 20
    TxtStr "Hello World!"
    TxtObj (vlax-invoke-method CModelSpace 'addtext TxtStr
    (vlax-3D-point InPt) TxtHt)
    );setq

    (vlax-put-property TxtObj 'alignment acAlignmentCenter)
    (vlax-put-property TxtObj 'textalignmentpoint (vlax-3D-point InPt))
    (vlax-put-property TxtObj 'alignment acAlignmentCenter)
    (vlax-put-property TxtObj 'height 1)
    (vlax-invoke-method NewDoc 'regen acactiveviewport)
    (vlax-put-property TxtObj 'height txtht)
    (vlax-invoke-method NewDoc 'regen acactiveviewport)


    Dazed and confused!
     
    Bob, Jan 6, 2005
    #1
  2. I'm pretty sure that the document you're working in
    needs to be the Active document. Testing the same
    code on text in the active document should confirm
    that.
     
    Tony Tanzillo, Jan 6, 2005
    #2
  3. Bob

    Alaspher Guest

    You should do vla-update for object like:
    Code:
    (defun test (/             ACADCOLLECTION              CMODELSPACE   INPT
    LAYERCOLLECTION             NEWDOC        TESTLAYER     TXTHT
    TXTOBJ        TXTSTR
    )
    (setq ACADCollection  (vla-get-Documents (vlax-get-acad-object))
    NewDoc          (vla-Add ACADCollection)
    CModelSpace     (vla-get-ModelSpace NewDoc)
    LayerCollection (vla-get-Layers NewDoc)
    testLayer       (vla-add LayerCollection "testing")
    InPt            (vlax-3D-point (list 50 50 0))
    TxtHt           20
    TxtStr          "Hello World!"
    TxtObj          (vla-addtext CModelSpace TxtStr InPt TxtHt)
    )
    (vla-put-alignment TxtObj acAlignmentCenter)
    (vla-put-textalignmentpoint TxtObj InPt)
    (vla-put-alignment TxtObj acAlignmentCenter)
    (vla-put-height TxtObj 1)
    (vla-put-height TxtObj txtht)
    (vla-update TxtObj)
    )
    best regards
     
    Alaspher, Jan 7, 2005
    #3
  4. Bob

    Bob Guest

    Thanks for the feedback Alaspher.

    I've tried both ways. Using vla and vlax. Using the code you posted here
    still gives the same result. The text displays as default 'left' aligned
    but when you list it's properties ACAD shows the alignment to be 'center'.

    Just out of curiousity, what is the benefit of using vla over vlax? I'm
    pretty new to all this.

    Thanks again for the help.
     
    Bob, Jan 7, 2005
    #4
  5. Bob

    Alaspher Guest

    If you want to put centred text in the valid position, then your code should be like this:
    Code:
    (defun test (/            ACADCOLLECTION            ALPT         CMODELSPACE
    INPT         LAYERCOLLECTION           MAXP         MINP
    NEWDOC       TESTLAYER    TXTHT        TXTOBJ       TXTSTR
    )
    (setq ACADCollection  (vla-get-Documents (vlax-get-acad-object))
    NewDoc          (vla-Add ACADCollection)
    CModelSpace     (vla-get-ModelSpace NewDoc)
    LayerCollection (vla-get-Layers NewDoc)
    testLayer       (vla-add LayerCollection "testing")
    InPt            (vlax-3D-point (list 50 50 0))
    TxtHt           20
    TxtStr          "Hello World!"
    TxtObj          (vla-addtext CModelSpace TxtStr InPt TxtHt)
    )
    (vla-GetBoundingBox TxtObj 'MinP 'MaxP)
    (setq MinP (vlax-safearray->list MinP)
    MaxP (vlax-safearray->list MaxP)
    AlPt (vlax-3D-point (list (/ (+ (car MinP) (car MaxP)) 2) (cadr MinP) (caddr MinP)))
    )
    (vla-put-alignment TxtObj acAlignmentCenter)
    (vla-put-TextAlignmentPoint TxtObj AlPt)
    (vla-move TxtObj AlPt InPt)
    (vla-update TxtObj)
    (princ)
    )
    vla-* is just easy for using (more readable) and vlax-* more universally, but in the simple code are redundant. In my opinion.

    Best Regards
     
    Alaspher, Jan 7, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.