Results 1 to 3 of 3

Thread: Selection through Text or Mtext

  1. #1
    Member
    Join Date
    2020-07
    Posts
    14
    Login to Give a bone
    0

    Default Selection through Text or Mtext

    Hello Everyone.

    Please check this code there seems to be a probelm everytime i select text or Mtext it will only generate
    one iteration. What i want it for it to go through texts of any kind. and dump for me on Excel sheet.

    here is some line of code i have gone so far. I have attached the drawing and Excel Macro code.

    I want help for this to work.
    Thank you.

    Code:
    Sub get_staiton()
        Dim objDrawingObject As AcadText
        Dim objDrawingObj As AcadMtext
        Dim objSS As AcadSelectionSet
        ' i created here a random characters to add as a selection set name
    Range("b1").Formula = "=CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))&CHAR(RANDBETWEEN(67,90))"
        yu = Range("b1").Value
         Range("c1").Value = yu
         
                With ActiveDocument.Utility
                    '' create a new selectionset
                    Set objSS = ActiveDocument.SelectionSets.Add(yu)
                    '' let user select entities interactively
                    objSS.SelectOnScreen
                    .Prompt vbCr & objSS.Count & " entities selected"
                End With
        
        
        ' iterate selection...
        n = 1
            On Error Resume Next
    
                For Each objDrawingObj In objSS
                    y = objDrawingObj.TextString
                         Cells(4 + n, 1) = y
                         n = n + 1
                Next
    
        n = 1
                For Each objDrawingObject In objSS
                    y = objDrawingObject.TextString
                         Cells(4 + n, 1) = y
                         n = n + 1
                Next
    End Sub
    Attached Files Attached Files
    Last edited by rkmcswain; 2020-08-10 at 07:48 PM. Reason: Added [CODE] tags

  2. #2
    Member
    Join Date
    2009-04
    Posts
    13
    Login to Give a bone
    0

    Default Re: Selection through Text or Mtext

    You should only do the "For Each...Next" loop once, by iterating the SelectionSet as AcadEntity, not AcadText or AcadMText (because when user does the selecting on screen, he/she could select any thing, beside Text/MText. So the code should be like

    Dim ent As AcadEntity
    Dim textEnt As AcadText
    Dim mtextEnt As AcadMText

    '' Create SelectionSet and do the selecting here
    ...

    For Each ent in objSS
    If TypeOf ent Is AcadText Then
    Set textEnt = ent
    '' Do whatever wuth the AcadText object
    ElseIf TypeOf ent Is AcadMText Then
    Set mtextEnt = ent
    '' DO whatever with the AcadMText object
    End If
    Next
    ...

    '' Delete the selectionset after you are done with it
    ...

  3. #3
    Member
    Join Date
    2020-07
    Posts
    14
    Login to Give a bone
    0

    Default Re: Selection through Text or Mtext

    That was a good one.
    Thank you.

Similar Threads

  1. Replies: 0
    Last Post: 2012-04-18, 05:43 PM
  2. Select NavisWorks items in Selection Tree through COM API
    By daryappa.madasnal188858 in forum NavisWorks - General
    Replies: 0
    Last Post: 2009-03-18, 03:40 PM
  3. families not getting cut through/getting cut through
    By rjcoolpix880 in forum Revit Architecture - General
    Replies: 4
    Last Post: 2006-12-05, 06:04 PM
  4. Strike-through in MText and single line Text
    By lem_102074329 in forum AutoCAD General
    Replies: 1
    Last Post: 2006-10-18, 05:54 AM
  5. Getting ADT Schedule "Selection Set" through VBA
    By jonesb33145 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2005-03-19, 12:16 AM

Posting Permissions

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