Author Topic: Next step. Get attributes, and sort them  (Read 3116 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Next step. Get attributes, and sort them
« on: January 06, 2006, 06:00:41 PM »
With the help of Glan and Jeff I have the portion of code now to grab my title block.  I looked through other post, and the help, and couldn't really figure out if I was doing this correctly.  In my lisp I make a list of list of the revision attributes, and then sort that list so that I know where to put the new one.  I have started that phase with VBA, but I am stuck.  I have put the attributes I need into variants (hope that what they should be), but I don't know how to sort them by the first value of the variants.  I was thinking that I would put the three variants into one main variant (safearry?) and sort that one, and move one from there, but I don't see how to sort.  The problem with my sorting is that they can be numbers or alphas, but one per type of drawing.  So if one revision is a number, all of them are numbers.  Okay enough of me talking, here is my code so far.
Code: [Select]
Public Sub ApplyRevision(AttVar As Variant)
    Dim Level1(0 To 5) As AcadAttribute
    Dim Level2(0 To 5) As AcadAttribute
    Dim Level3(0 To 5) As AcadAttribute
   
    Level1(0) = AttVar(0): Level1(1) = AttVar(1): Level1(2) = AttVar(2): Level1(3) = AttVar(3): Level1(4) = AttVar(4): Level1(5) = AttVar(5)
    Level2(0) = AttVar(6): Level2(1) = AttVar(7): Level2(2) = AttVar(8): Level2(3) = AttVar(9): Level2(4) = AttVar(10): Level2(5) = AttVar(11)
    Level3(0) = AttVar(12): Level3(1) = AttVar(13): Level3(2) = AttVar(14): Level3(3) = AttVar(15): Level3(4) = AttVar(16): Level3(5) = AttVar(17)
   
End Sub
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Next step. Get attributes, and sort them
« Reply #1 on: January 06, 2006, 08:27:42 PM »
There are a number of Array sorting funtions out there. The one I use most is "Bubble sort", if a search doesn't turn it up, I can post it here. If what you need to sort is a large amount of data, one of the others would be better suited, as Bubble Sort really isn't very fast. HERE'S a link that demonstrates how Bubble Sort works.

Could you post the lisp code and some sample returned data or the drawing for this portion? I'm unclear as to what you are doing...why the 3 levels?

Oh, and it's Glenn :-P

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Next step. Get attributes, and sort them
« Reply #2 on: January 07, 2006, 06:40:44 AM »
Shell sort sample:
Code: [Select]
'
' - Function MeSortArray
'  Description:
'     Sorts an array by order argument.
'   Arguments:
'     - ArtDat = Array
'     - SrtDir = Sort order
'                True =  Ascending
'                False = Descending
'   Return:
'     - None
'   Notes:
'     - None
'
Public Function MeSortArray(SrtDat() As Variant, SrtDir As Boolean)

    Dim MaxCnt As Long
    Dim ArrCnt As Long
    Dim SrcVal As Long
    Dim TarVal As Long
    Dim TmpVal As Variant
   
    MaxCnt = UBound(SrtDat)
    TarVal = MaxCnt \ 2
   
    While TarVal > 0
        For ArrCnt = 0 To MaxCnt - TarVal
            SrcVal = ArrCnt
            While IIf(SrtDir, _
                     (SrcVal >= 0) And (SrtDat(SrcVal) > SrtDat(SrcVal + TarVal)), _
                     (SrcVal >= 0) And (SrtDat(SrcVal) < SrtDat(SrcVal + TarVal)))
                TmpVal = SrtDat(SrcVal)
                SrtDat(SrcVal) = SrtDat(SrcVal + TarVal)
                SrtDat(SrcVal + TarVal) = TmpVal
                If SrcVal > TarVal Then
                    SrcVal = SrcVal - TarVal
                Else
                    SrcVal = 0
                End If
            Wend
        Next ArrCnt
        TarVal = TarVal \ 2
    Wend

End Function
« Last Edit: January 07, 2006, 06:44:53 AM by Jürg Menzi »
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Glenn R

  • Guest
Re: Next step. Get attributes, and sort them
« Reply #3 on: January 07, 2006, 09:55:53 AM »
Thankyou Jeff - people spelling my name incorrectly when it's there in front of them pisses me off no end.
I get inter-company emails with people spelling my name with 1 'n' - when they OBVIOUSLY look up my name in the global address book.....lack of respect in my opion.

Best Regards,
Glenn.

LE

  • Guest
Re: Next step. Get attributes, and sort them
« Reply #4 on: January 07, 2006, 09:26:32 PM »
Thankyou Jeff - people spelling my name incorrectly when it's there in front of them pisses me off no end.
I get inter-company emails with people spelling my name with 1 'n' - when they OBVIOUSLY look up my name in the global address book.....lack of respect in my opion. <<<--- ?

Best Regards,
Glenn.

A friend of mine name is Glen Otis, with one 'n'... it is difficult and one has to live with that.... I normally being call Louis with the O simple because of the pronunciation... Every time I go to buy my grande coffee [at 5:25 or 5:35 AM], I have to spell my name, because if I do not do it, they write LOuis in the cup...  :roll:
« Last Edit: January 08, 2006, 11:41:35 AM by LE »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Next step. Get attributes, and sort them
« Reply #5 on: January 09, 2006, 11:45:42 AM »
Thanks for all the help, but I think I will not be presueing this anymore.  Right now it doesn't look like the right time for me to learn VBA.  I might be able to do some stuff when I have free time, but then again it looks like I will need to pick up a book on the subject.

Thankyou Jeff - people spelling my name incorrectly when it's there in front of them pisses me off no end.
I get inter-company emails with people spelling my name with 1 'n' - when they OBVIOUSLY look up my name in the global address book.....lack of respect in my opion.

Best Regards,
Glenn.
I think Jeff was pointing out more that I spelled it completely wrong.  I put "Glan".  I'm sorry Glenn.  You have been a big help, and I do appreciate it.  No disrespect intended.

Thanks Jurg.  If I pick this up again I'm sure this will help.



Jeff,

The basic idea is, we only have three lines for revision history.  If all are filled up, then I need to move them down, and place the new one on top.  The problem is that some of the disciplines I work with don't put them in order.  They just cycle then, so the latest one might be one bottom of the revision block area.  So I would get all the information for the three levels (5 attributes), sort them, and put them in the right order with the new revision added.  I hope that clears it up.  If you still want to see the lisp code, I can post that no problem.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.