Results 1 to 6 of 6

Thread: Need some help with combo boxes and loading xrefs

  1. #1
    Member
    Join Date
    2006-06
    Location
    Los Angeles
    Posts
    3
    Login to Give a bone
    0

    Default Need some help with combo boxes and loading xrefs

    Hello everyone, I'm working on a program that will pop up a form when a drawing is opened, and then will allow the user to select which xrefs are to be loaded from combo boxes.

    The reason for this is we have a customizable product, and instead of going through and making a drawing for every combination possible (there will eventually be hundreds), I'd like to have a form that does it automatically when a new module is ordered. Most of the components (around 20) are already drawn, so what I'm thinking is that all the different parts will be attached as xrefs, the form will load the desired xrefs.

    Anyway, I seem to be gradually learning this when I have time, and this place and the tutorials I've found are pretty helpful, but I'm having trouble getting the combo boxes to work the way I want. Plus I'd like to make it so once the first selection is made, the next combo box (there will be three) only displays the compatible components.

    I suppose that once I get a little farther into it I'll have some more specific questions, but as of now I'm just kind of looking around and finding some code that sort of does what I want and combining it all together. I feel like there is a more, uh, elegant way to do it, and was checking in to see if anyone had done anything like this before or had any tips. We're on AutoCAD 2000 and are switching to solidworks soon apparantly, but since mostly everything is already drawn I want to do this in autocad.

    Thanks.
    Last edited by peterleclaire; 2006-07-06 at 06:40 PM.

  2. #2
    Member
    Join Date
    2002-05
    Posts
    47
    Login to Give a bone
    0

    Default Re: Need some help with combo boxes and loading xrefs

    Hello peterleclaire

    The simple solution to your combobox display question could be:

    Code:
    Private Sub ComboBox1_Change()
    
    UserForm1.ComboBox2.Clear
    
    If UserForm1.ComboBox1.Value = "One" Then
        UserForm1.ComboBox2.AddItem "Three"
        UserForm1.ComboBox2.AddItem "Four"
    ElseIf UserForm1.ComboBox1.Value = "Two" Then
        UserForm1.ComboBox2.AddItem "Five"
        UserForm1.ComboBox2.AddItem "Six"
    ........ 
    End If
    End Sub
    The code will grow according to the number of choices, and could maybe be made more elegant, but it works.

    Hope it helps.

    Regards Claus
    Last edited by cll; 2006-07-10 at 07:32 AM. Reason: [CODE] tags added

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Need some help with combo boxes and loading xrefs

    Using If statements will not allow it to 'grow' very well. I suggest using Select...Case instead. In addition to being structured for many branches as opposed to 2 or 3, with If, all branches must be evaluated. With Select, evaluation of the Case's stops when a match is found.
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member
    Join Date
    2006-06
    Location
    Los Angeles
    Posts
    3
    Login to Give a bone
    0

    Default Re: Need some help with combo boxes and loading xrefs

    Quote Originally Posted by Ed Jobe
    Using If statements will not allow it to 'grow' very well. I suggest using Select...Case instead.
    Yeah, that's what I was thinking. Also it might be better to start with no attached xrefs, and then just attach the ones I want, and have it save as a new drawing. That way I wouldn't have to deal with some way of making sure only the ones I want are loaded (which probably won't be a problem as the original will be read only). I seem to be making progress anyway, thanks for the input everyone.

    Okay, now this code I found in the help file doesn't work. I don't really understand it yet:

    Code:
    Private Sub CommandButton1_Click()
        Select Case ComboBox1.Value
        
        Case "1.5 TC x 1.5 TC"
        InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
        Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(
    pathname1, "1.5 TC x 1.5 TC", InsertPoint, 1, 1, 1, 0, True)
        
        Case "1.5 TC x 0.5 HB"
        InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
        Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(
    pathname2, "1.5 TC x 0.5 HB", InsertPoint, 1, 1, 1, 0, True)
      
        Else: MsgBox "please select connections"
    End Sub
    _____________
    Private Sub UserForm_Initialize()
        UserForm1.ComboBox1.AddItem "1.5 TC x 1.5 TC"
        UserForm1.ComboBox1.AddItem "1.5 TC x 0.5 HB"
        
        Dim InsertPoint(0 To 2) As Double
        Dim insertedBlock As AcadExternalReference
        Dim tempBlock As AcadBlock
        Dim msg As String
        Dim pathname1 As String
        Dim pathname2 As String
        pathname1 = "S:\Eng\Peter L\plus xref\15tc15tc.dwg"
        pathname2 = "S:\Eng\Peter L\plus xref\15tc05hb.dwg"
        
    End Sub
    Right now I just want to get it working with one combobox and two options.
    Is it just not recognizing the combobox1.value because I still need to tell it what to do when the combobox changes?

    Well, anyway, I ordered an autocad vba book, so that should be helpful.
    Last edited by peterleclaire; 2006-07-10 at 03:41 PM.

  5. #5
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Need some help with combo boxes and loading xrefs

    Peter

    Try this way:

    Code:
     
    Private Sub CommandButton1_Click()
    	Dim InsertPoint(0 To 2) As Double
    	Dim insertedBlock As AcadExternalReference
    	Dim tempBlock As AcadBlock
    	Dim msg As String
    	Dim pathname1 As String
    	Dim pathname2 As String
    	pathname1 = "S:\Eng\Peter L\plus xref\15tc15tc.dwg"
    	pathname2 = "S:\Eng\Peter L\plus xref\15tc05hb.dwg"
     
    	Select Case ComboBox1.Value
    		Case "1.5 TC x 1.5 TC"
    			InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
    			Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference _
    			(pathname1, "1.5 TC x 1.5 TC", InsertPoint, 1, 1, 1, 0, False)
    		Case "1.5 TC x 0.5 HB"
    			InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
    			Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference _
    			(pathname2, "1.5 TC x 0.5 HB", InsertPoint, 1, 1, 1, 0, False)
    		Case Else: MsgBox "please select connections"
    	End Select
    End Sub
     
    Private Sub UserForm_Initialize()
    	UserForm1.ComboBox1.AddItem "1.5 TC x 1.5 TC"
    	UserForm1.ComboBox1.AddItem "1.5 TC x 0.5 HB"
    End Sub
    Regards,
    Abdul

  6. #6
    Member
    Join Date
    2006-06
    Location
    Los Angeles
    Posts
    3
    Login to Give a bone
    0

    Default Re: Need some help with combo boxes and loading xrefs

    Quote Originally Posted by abdulhuck
    Try this way:
    Worked perfectly, thanks a lot.

Similar Threads

  1. Replies: 9
    Last Post: 2017-10-16, 04:27 PM
  2. AutoCAD 2013: Xrefs Not Loading
    By craig.204376 in forum AutoCAD General
    Replies: 3
    Last Post: 2014-12-03, 12:55 PM
  3. Combo boxes in a titleblock
    By JILee in forum VBA/COM Interop
    Replies: 3
    Last Post: 2007-09-21, 01:34 PM
  4. Xrefs not loading between different users
    By r_soula in forum AutoCAD General
    Replies: 7
    Last Post: 2006-11-08, 03:31 PM
  5. Loading Xrefs come in at different locations
    By dlash in forum AutoCAD General
    Replies: 3
    Last Post: 2006-02-06, 05:07 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
  •