TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Register
 
The purpose of these forums is to discuss TurboCAD.  Please keep the discussion of other products to compatibility issues or how the other software’s can be used with TurboCAD.


Insert items into a drawing using VBA
Read 828 times
* May 08, 2016, 06:57:25 PM
I have successfully used a VBA script running from Microsoft Excel to insert a text item into a TurboCAD drawing.  However, instead of assigning all the properties (i.e. font) to the item in VBA, I want to use the current TurboCAD settings for text.  The only things I want to provide are the location and the actual text.

I also would like to change the text anchor point (i.e. top left)

Finally, I would like to change the TurboCAD settings so that if I manually add something to the drawing in TurboCAD, it matches the settings I am using in VBA.

Logged
"Nothing ever comes to one, that is worth having, except as a result of hard work."

--Booker T. Washington,
American educator and political leader


* May 27, 2016, 02:41:45 AM
#1
I use the clipboard to bring text into TC with the current settings.
==============================================================
   Dim oData As New DataObject
   On Error Resume Next
   oData.GetFromClipboard
   HoleTextVonZwischenablage = oData.GetText

Set Gr = Grs.AddText(HoleTextVonZwischenablage, X, Y, 0, 10 / 12)
=============================================================
To choose the place where to insert the text
Set App = IMSIGX.Application
Set Dr = App.ActiveDrawing
Set Grs = Dr.Graphics
Set V = Dr.Views(0)
Set Sel = Dr.Selection
Grs.Unselect
V.GetMouseClick X, Y
V.ViewToWorld X, Y, 0, x1, y1, 0
ActiveDrawing.Styles("Normal Lines").Activate
Set Gr = Grs.AddText(HoleTextVonZwischenablage, X, Y, 0)
Gr.MoveAbsolute x1, y1, 0
===================================
change anchor point
Selected Text
For Each gxChild in Selection
   gxURec.AddGraphicForModify gxChild
   gxChild.Properties("TextFormat") = 514  ‘from topLeft to Middle
Next

Standard Attribute for Text
Set gxStyle = ActiveDrawing.Styles("Normal Text")
gxStyle.Properties("TextFormat") = 514 ‘from topLeft to Middle


The macrorecorder is not really compatible with vba , but for me it is helpfull. It give an idea where and how to search.

Logged