acad386bis Posted March 4, 2014 Posted March 4, 2014 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 Quote
fixo Posted March 5, 2014 Posted March 5, 2014 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 Quote
RICVBA Posted March 6, 2014 Posted March 6, 2014 fine sorting sub fixo. I also posted a possible solution to acad386bis problem at http://forums.autodesk.com/t5/Visual-Basic-Customization/VBA-tri-le-TXT-in-bloc-dans-listbox-idem-bloc-%C3%A9cran/td-p/4855179 where I used a sorting sub managing a matrix instead of an array, developed for a more general use. but I'll certainly enhance that sub using ideas coming from yours thanks bye Quote
acad386bis Posted March 10, 2014 Author Posted March 10, 2014 Block Texts sorting.zip Is no good look the file attachement Quote
RICVBA Posted March 10, 2014 Posted March 10, 2014 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 Quote
acad386bis Posted March 14, 2014 Author Posted March 14, 2014 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 Quote
Recommended Posts
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.