Jump to content

Recommended Posts

Posted

hello

in autocad block 4 line TXT

TXT1 (handle # 3)

TXT2 (handle # 2)

TXT3 (handle No. 4)

TXT4 (handle # 1)

 

When I recuper the string in a combobox it puts me in the order of handle

TXT4,2,1,3

I then I want in the order of the line screen TXT1,2,3,4

 

Thank you for your help

********

Bonjour

Dans le bloc autocad 4 lignes de TXT

TXT1 (handle N°3)

TXT2 (handle N°2)

TXT3 (handle N°4)

TXT4 (handle N°1)

 

Quand je recupere le string dans une combobox il me le met dans l'ordre du handle =>Ligne 4,2,1,3

alors que je je veux dans l'ordre de l'écran ligne 1,2,3,4

 

Merci pour votre aide

 

Public Sub LireTxt()

Dim objBloc As AcadBlock

Dim objEnt As AcadEntity

Dim objEntTxT As as AcadText

 

ThisDrawing.Utility.GetEntity objBlocRef, Pt1, "Sélectionnez le bloc à modifier :"

Set objBloc = ThisDrawing.Blocks(objBlocRef.Name)

 

For Each objEnt In objBloc

If objEnt.ObjectName = "AcDbText" Then

ListBoxTxt.AddItem objEntTxT.textString

Endif

Next

 

End Sub

Posted

Try this code, then rewrite this example to your needs:

 

Option Explicit
Option Compare Binary 'working with 'Option Compare Text' as well
  Sub BubbleSort(arr As Variant, Optional descending As Boolean, Optional numEls As Variant)
          ' Bubble Sort an array of any type
          ' Author: The VB2TheMax Team
          ' BubbleSort is especially convenient with small  arrays (1,000
          ' items or fewer) or with arrays that are  already almost sorted
          '
          ' NUMELS is the index of the last item to be sorted, and is
          ' useful if the array is only partially filled.
          '
          ' Works with any kind of array, except UDTs and fixed -Length
          ' strings, and including objects if your are sorting on their
          ' default property. String are sorted in case-sensitive mode.
          '
          ' You can write faster procedures if you modify the first two lines
          ' to account for a specific data type, eg.
           'Sub BubbleSortS(arr() As Single, Optional descending As Boolean, Optional numEls As Variant)
          ' Dim value As Single
          Dim Value As Variant
          Dim Index As Long
          Dim firstItem As Long
          Dim indexLimit As Long, lastSwap As Long
          ' account for optional arguments
          If IsMissing(numEls) Then numEls = UBound(arr)
          firstItem = LBound(arr)
          lastSwap = numEls
          Do
          indexLimit = lastSwap - 1
          lastSwap = 0
          For Index = firstItem To indexLimit
          Value = arr(Index)
          If (Value > arr(Index + 1)) Xor descending Then
          ' if the items are not in order, swap them
          arr(Index) = arr(Index + 1)
          arr(Index + 1) = Value
          lastSwap = Index
          End If
          Next
          Loop While lastSwap
          End Sub
          
          
         Sub testSort()
         Dim strText As String
         
         Dim Items(3) As Variant
         Dim i
         Items(0) = "handle N°3"
         Items(1) = "handle N°1"
         Items(2) = "handle N°2"
         Items(3) = "handle N°4"
         
         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
         'Sort array by descending:
         BubbleSort Items, False
         '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
         
         For i = LBound(Items) To UBound(Items)
         Debug.Print Items(i)
         Next i
         End Sub

Posted

Awesome work,

Thanks for your solution

Cheers :)

Posted

I attach revised version as I got your request

 

instead of "handle" property, I saved text insertipon point "Y" coordinate in "Texts" matrix first column. then I asked dhBubbleSort2D to sort by first column (and added ascending/descending sortering order parameter)

 

bye

Block Texts sorting-rev 10_03_2014 RICVBA.dwg

Posted

RICVBA thank you!

 

 

 

 

So cool this forum ...

The code is really pretty, it's been fun to read.

It was not so complicated to final

thank you again

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...