Results 1 to 4 of 4

Thread: VBA import Text

  1. #1
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default VBA import Text

    I tried the code for importing the text data This may be someone can help and add text rotation 90" and positioned in the middle left this my code;
    Code:
    Sub Xxxx()     Dim ACAD As AcadApplication     Dim txObj As acadText     Dim ws As Range     Dim CrdNo(0 To 2) As Double     Dim TxNo As String     Dim hNo As Double     Dim LastRow As Double     Dim i As Integer     Dim j As Integer     Dim k As Integer     Set ACAD = GetObject(, "AutoCAD.Application")     Set ws = Worksheets("NUM").Cells     LastRow = ws(Rows.Count, 20).End(xlUp).Row     hNo = 0.3            For i = 2 To LastRow          j = 20          CrdNo(0) = ws(i, j): CrdNo(1) = ws(i, j + 1): CrdNo(2) = "0"          TxNo = ws(i, j)       Next i       Set txObj = ACAD.ActiveDocument.ModelSpace.AddText(TxNo, CrdNo, hNo)   End Sub
    sorry i has edit my code and then im waiting for your help to rotated text Thanks For Help
    Last edited by Iyant; 2014-03-06 at 02:18 PM.

  2. #2
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Re: VBA import Text

    Code:
    Sub Xxxx() 
         Dim ACAD As AcadApplication
         Dim txObj As acadText
         Dim ws As Range 
         Dim CrdNo(0 To 2) As Double
         Dim TxNo As String
         Dim hNo As Double 
         Dim LastRow As Double
         Dim i As Integer
         Dim j As Integer 
         Dim k As Integer
         Set ACAD = GetObject(, "AutoCAD.Application")
         Set ws = Worksheets("NUM").Cells
         LastRow = ws(Rows.Count, 20).End(xlUp).Row
         hNo = 0.3 
              For i = 2 To LastRow 
              j = 20
              CrdNo(0) = ws(i, j): CrdNo(1) = ws(i, j + 1): CrdNo(2) = "0"
              TxNo = ws(i, j)
           Set txObj = ACAD.ActiveDocument.ModelSpace.AddText(TxNo, CrdNo, hNo)
           Next i
    End Sub
    Last edited by Ed Jobe; 2014-03-06 at 03:18 PM. Reason: Added code tags

  3. #3
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

    Default Re: VBA import Text

    add
    Code:
    txObj.Rotation = 0.707 '  or whatever angle, in radians, you need. (.707 radians=45 degrees)
    just after
    Code:
    Set txObj = ACAD.ActiveDocument.ModelSpace.AddText(TxNo, CrdNo, hNo)
    I'd also suggest you to consider the following
    1) with
    Code:
    CrdNo(2) = "0"
    you're assigning a string value to a double one.
    maybe you'd rather code
    Code:
    CrdNo(2) = 0#
    2) with
    Code:
    TxNo = ws(i, j)
    you're assigning what is supposed to be a double value to a string one.
    if you actually want the text string to reflect the x coordinate than you'd rather code
    Code:
    TxNo = cstr(ws(i, j))
    3) since j=20 never changes inside the i-loop, you'd better place that line just before starting the loop

    bye

  4. #4
    Member
    Join Date
    2014-01
    Posts
    16
    Login to Give a bone
    0

    Default Re: VBA import Text

    thankyou very much RICVBA, this code has work now..
    *Thumbs Up*

Similar Threads

  1. Import and Export Text to dwg
    By Simon.Whitbread in forum Revit - Platform
    Replies: 1
    Last Post: 2010-09-23, 02:27 PM
  2. import text file values
    By KHADREE_SHARIFF in forum AutoLISP
    Replies: 1
    Last Post: 2007-06-25, 08:05 AM
  3. Text Import from Word
    By boofredlay in forum Revit Architecture - General
    Replies: 2
    Last Post: 2007-01-18, 04:53 PM
  4. DWG Import Detail Text Problems
    By djn in forum Revit Structure - General
    Replies: 8
    Last Post: 2007-01-15, 12:32 PM
  5. Import text font...
    By gjburkett in forum Revit Architecture - General
    Replies: 6
    Last Post: 2005-01-27, 10:14 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
  •