Author Topic: Total newby to the swamp... VB block insertion  (Read 33648 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #15 on: December 22, 2005, 05:49:42 PM »
In my haste to get out of town I forgot to add that I would use 1 listbox for each of the different sets of blocks you have. Place them on top of each other and make only 1 visible at a time. So in the Click Event of each Optionbutton it would have something like this:
Code: [Select]
Sub SheetOption_Click ()
If SheetOption.Value = True Then
  SheetListbox.Visble = True
  'All other Listboxes must be set to False
Else
  SheetListbox.Visible = False
End If
End Sub

And I do hope I didn't scare you away......  8-) Have a Merry Christmas!

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #16 on: December 22, 2005, 06:00:25 PM »
Jeff,

No, you have not scared me away. I actually found a book on VB6 and I am begining to understand some of the lingo I have heard. I am trying to understand and my attention to any one thing is diminished when I have to pull out the fire hose to put out the latest fire around here.

I will be off and on with this for a while, but yet again... I am in no hurry and I think it is more important I make a good effort to understand what it is that I am doing rather than cut and paste someones code. Your help is "Greatly" appreciated and I must say a refreshing escape from the norm on another forum...** Clears Throat **.

Thank you Jeff and others and have a Merry Christmas/Holiday.

akdrafter

  • Guest
VB block insertion revisited...
« Reply #17 on: May 18, 2006, 02:49:07 PM »
Hello,

I am revisiting this thread because I basically dropped it and I am now trying to pick it back up.

Jeff.... I have the following code from your example of reading the contents of the text file at Initialize time and your advise about making only the current list box visible is a good one but I can't seem to get it to work.

Suggestions?

I have attached the dvb and the 3 text files.

AKDrafter


Code: [Select]
Option Explicit
Dim arrName1() As String
Dim arrName2() As String
Dim arrName3() As String
Const MyPath As String = "C:\"


Private Sub UserForm_Initialize()
Dim arrType1() As String
Dim arrType2() As String
Dim arrType3() As String
Dim strTmp As String
Dim fFile As Integer
Dim I As Long

ReDim arrType1(0 To 999)
ReDim arrName1(0 To 999)
ReDim arrType2(0 To 999)
ReDim arrName2(0 To 999)
ReDim arrType3(0 To 999)
ReDim arrName3(0 To 999)

fFile = FreeFile

'**** Type 1
Open MyPath & "_Type1.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 3
    Line Input #fFile, strTmp
Next
I = 0
Line Input #fFile, strTmp
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType1(I) = Replace(strTmp, "*", "")
    Line Input #fFile, strTmp
    arrName1(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType1(0 To I - 1)
ReDim Preserve arrName1(0 To I - 1)
ListBox1.List = arrType1
'End of Type 1

'**** Type 2
Open MyPath & "_Type2.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 3
    Line Input #fFile, strTmp
Next
I = 0
Line Input #fFile, strTmp
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType2(I) = Replace(strTmp, "*", "")
    Line Input #fFile, strTmp
    arrName2(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType2(0 To I - 1)
ReDim Preserve arrName2(0 To I - 1)
ListBox2.List = arrType2
'End of Type 2

'**** Type 3
Open MyPath & "_Type3.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 3
    Line Input #fFile, strTmp
Next
I = 0
Line Input #fFile, strTmp
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType3(I) = Replace(strTmp, "*", "")
    Line Input #fFile, strTmp
    arrName3(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType3(0 To I - 1)
ReDim Preserve arrName3(0 To I - 1)
ListBox3.List = arrType3
'End of Type 3

End Sub

Private Sub CancelButton_Click()
End
End Sub

Sub OptionButton1_Click()
If OptionButton1.Value = True Then
    ListBox1.Visible = True
Else
    ListBox1.Visible = False
End If
End Sub

Sub OptionButton2_Click()
If OptionButton2.Value = True Then
    ListBox2.Visible = False
Else
    ListBox2.Visible = True
End If
End Sub

Sub OptionButton3_Click()
If OptionButton3.Value = True Then
    ListBox3.Visible = False
Else
    ListBox3.Visible = True
End If
End Sub

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #18 on: May 18, 2006, 03:03:45 PM »
 :-D Yes... the list box visible settings are tweaked a bit...hahahahaah

I think it should be something like this.

Code: [Select]
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
    ListBox1.Visible = True
Else
    ListBox1.Visible = False
End If
End Sub

Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
    ListBox2.Visible = True
Else
    ListBox2.Visible = False
End If
End Sub

Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
    ListBox3.Visible = True
Else
    ListBox3.Visible = False
End If
End Sub

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #19 on: May 18, 2006, 03:27:34 PM »
Ok. Solving my own problems...hahahahaah

This works, but I am not sure if it is the most effective or correct way to hide/make visible each list box based on which OptionButton is picked.

Code: [Select]
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
    ListBox1.Visible = True
    ListBox2.Visible = False
    ListBox3.Visible = False
End If
End Sub

Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
    ListBox2.Visible = True
    ListBox1.Visible = False
    ListBox3.Visible = False
End If
End Sub

Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
    ListBox3.Visible = True
    ListBox1.Visible = False
    ListBox2.Visible = False
End If
End Sub

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #20 on: May 18, 2006, 03:47:04 PM »
Keep talkin' Tim and all your problems will be solved :-)

I'm gonna have a look-see right now.


akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #21 on: May 18, 2006, 03:50:49 PM »
Thanks Jeff. I am moving on to the insertion part now.

Fingers crossed.

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #22 on: May 18, 2006, 04:15:21 PM »
OK, back to the form.....first, to make typing easier (i.e.-use copy-paste) I usually keep all of my Optionbutton's code in the same order. That way I set up the first one, then copy-paste it however many times I have additional buttons, then just change the number and the actions. Not that big a deal, but I really don't like to type more than necessary.....

Second, I'm attaching the form & code how I'd do it. Note that I stacked all 3 listboxes on top of each other..........

I also added default selected items so if the user presses insert before they actually select something, at least something will be done...an error would be thrown otherwise.

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #23 on: May 18, 2006, 04:44:48 PM »
Jeff,

I see how you set the "properties" using code instead of setting the the property via the properties. If that makes sense. hahahaha

I had the list boxes and their option buttons spread out so that I could see the on/off of the list boxes. I have since lined things up and such.

Now concerning the insertion part of the routine. Is this how I would store the value of the block to be inserted?

blkName = arrName3(ListBox3.ListIndex)

Code: [Select]
'**** Type 3
Open MyPath & "_Type3.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 3
    Line Input #fFile, strTmp
Next
I = 0
Line Input #fFile, strTmp
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType3(I) = Replace(strTmp, "*", "")
    Line Input #fFile, strTmp
    arrName3(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType3(0 To I - 1)
ReDim Preserve arrName3(0 To I - 1)
ListBox3.List = arrType3
blkName = arrName3(ListBox3.ListIndex)
'End of Type 3

Would I add that to each type and then I would have the "blkName" to use as the variable in an insertion function?

Also, I am thinking of adding a line to the "Type" text file after or before the "actual" block name to be inserted that would have layer properties (name,color & linetype) that I could also feed to the insertion function.

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #24 on: May 18, 2006, 05:07:53 PM »
This is how I would use the blkName variable.....first I'd declare it as a Global, then at the end iof the initialize event:
Code: [Select]
ListBox3.List = arrType3
'End of Type 3
''Provide a default button, usually the first in the list
OptionButton1.Value = True
ListBox1.Visible = True
ListBox1.Selected(0) = True
blkName = arrname(ListBox1.ListIndex)
ListBox2.Visible = False
ListBox2.Selected(0) = True
ListBox3.Visible = False
ListBox3.Selected(0) = True
End Sub
Then for each ListBoxX_Click event:
Code: [Select]
Private Sub ListBox1_Click()
blkName = arrName1(ListBox1.ListIndex)
End Sub
Private Sub ListBox2_Click()
blkName = arrName2(ListBox2.ListIndex)
End Sub
Private Sub ListBox3_Click()
blkName = arrName3(ListBox3.ListIndex)
End Sub

Adding the property information cold be done fairly easily, too. Will all of the Type1 blocks go on the same layer with the same color & linetype, or will each one be different?

Ya know, I sometimes wonder at how I arrive at some of my decisions.....thinking back on the Listboxes.......crud, I should've thought this way originally. I'll post something new for you to chew on in a few.....

You will probably want to hunt me down to bop me upside the head, but......

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #25 on: May 18, 2006, 05:59:19 PM »
To answer your question about the layering for the different types...

Some....hahahaha

Type1 = Layer1
Type2 = Layer2
Type3 = Layer3
Type4 = Various Layers

So, that is why my thought is to add the layer properties in the text file next to the actual block name to be inserted. There would be other items that could be useful. Like rotation, scale based on paper or model space, mirrioring, etc. So, my thought was that if I knew how to set the layer props in the text file, I would understand how to set the other items within the text file as well. I used the code from Kerry to have the various props set via the image tile menu before the insertion routine begins. So, it was definately much easier to set the various props of the different kinds of blocks to be inserted.

The insertion code Kerry Brown wrote:

Code: [Select]
(defun BLKINS (LA_NAM LA_COL LA_LT BLKNAM INSSCL ROT MIR ATTS EXP / INSPT)
(INITERR)
(setvar "cmdecho" 0)
(vl-load-com)
(command ".undo" "end")
(command ".undo" "m")
(setvar "cecolor" "bylayer")
(setvar "celtype" "bylayer")
(setvar "celweight" -1)
(setvar "snapmode" 0)
(setvar "attreq" 0)
;;;
(or INSSCL (setq INSSCL (getvar "dimscale")))
;;;
(setq INSPT (getpoint "\nPick Insertion Point: "))
;;;
(vl-cmdf ".-layer" "make" LA_NAM "thaw" LA_NAM "on" LA_NAM "color" LA_COL LA_NAM "lt" LA_LT LA_NAM "")
;;;
(if ROT
(vl-cmdf ".-insert" BLKNAM INSPT INSSCL INSSCL ROT)
   (progn
   (princ "\nRotation Angle: ")
   (vl-cmdf ".-insert" BLKNAM INSPT INSSCL INSSCL pause)
   )
)
;;;
(if MIR
   (vl-cmdf ".mirror" (entlast) "" INSPT pause "y")
)
;;;
(if ATTS
(vl-cmdf ".ddatte" (entlast))
)
;;;
(if EXP
(vl-cmdf ".explode" (entlast))
)
;;;
(command ".undo" "end")
(RESET)
(princ)
)

Jeff_M

  • King Gator
  • Posts: 4042
  • C3D user & customizer
Re: Total newby to the swamp... VB block insertion
« Reply #26 on: May 18, 2006, 07:30:38 PM »
OK, here's a different spin on the Listboxes and Text files. It utilizes just one listbox, no matter how many different block TYPES you want to include. It does require a separate, global, Array for each Type. ALso, since each row from the text file is converted to and array of rows & columns, when you add more "columns" to the text file you will need to make sure to update that number in the ReDim of the arrays. Take a look and see how you will be able to grab all of the data you need for each insertion quite easily. This still uses your same form, but I removed the ListBoxes 2 & 3. Make sure to modify your Text files as I noted in the code.
Code: [Select]
'This version uses only 1 listbox......and changes how the TEXT file is arranged _
  which will allow for easy expansion for the scale, rotation, etc.
'Typical text file:

'--------------------
'Type 1
'--------------------
'Description,BlockName,Layer,Color,Linetype
'Type1-1,Block1,Layer1,2,CONTINUOUS
'Type1-2,Block2,Layer1,2,CONTINUOUS
'Type1-3,Block3,Layer1,2,CONTINUOUS
'Type1-4,Block4,Layer1,2,CONTINUOUS
'Type1-5,Block5,Layer1,2,CONTINUOUS
'
'--------------------
'Type 1
'--------------------

Option Explicit
Dim arrName1() As Variant
Dim arrName2() As Variant
Dim arrName3() As Variant
Dim blkName As String
Dim blkColor As Integer
Dim blkLayer As String
Dim blkLType As String
Const MyPath As String = "C:\"

Private Sub CommandButton1_Click()
Debug.Print blkName & " " & blkLayer
End Sub

Private Sub ListBox1_Click()
Dim I As Integer
I = ListBox1.ListIndex
blkName = ListBox1.List(I, 1)
blkLayer = ListBox1.List(I, 2)
blkColor = ListBox1.List(I, 3)
blkLType = ListBox1.List(I, 4)
End Sub

Private Sub UserForm_Initialize()
Dim arrType1() As String
Dim arrType2() As String
Dim arrType3() As String
Dim arrTmp As Variant
Dim strTmp As String
Dim fFile As Integer
Dim I As Long

ReDim arrType1(0 To 999)
ReDim arrType2(0 To 999)
ReDim arrType3(0 To 999)

fFile = FreeFile

'**** Type 1
Open MyPath & "_Type1.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 4
    Line Input #fFile, strTmp
Next
I = 0
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType1(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType1(0 To I - 1)
ReDim arrName1(0 To I - 1, 0 To 4)
For I = 0 To UBound(arrType1)
    arrTmp = Split(arrType1(I), ",")
    arrName1(I, 0) = arrTmp(0)
    arrName1(I, 1) = arrTmp(1)
    arrName1(I, 2) = arrTmp(2)
    arrName1(I, 3) = arrTmp(3)
    arrName1(I, 4) = arrTmp(4)
Next
'End of Type 1

'**** Type 2
Open MyPath & "_Type2.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 4
    Line Input #fFile, strTmp
Next
I = 0
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType2(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType2(0 To I - 1)
ReDim arrName2(0 To I - 1, 0 To 4)
For I = 0 To UBound(arrType2)
    arrTmp = Split(arrType2(I), ",")
    arrName2(I, 0) = arrTmp(0)
    arrName2(I, 1) = arrTmp(1)
    arrName2(I, 2) = arrTmp(2)
    arrName2(I, 3) = arrTmp(3)
    arrName2(I, 4) = arrTmp(4)
Next
'End of Type 2

'**** Type 3
Open MyPath & "_Type3.txt" For Input As #fFile
'Need to skip the first 4 lines
For I = 0 To 4
    Line Input #fFile, strTmp
Next
I = 0
While strTmp <> "" 'this will stop it once it encounters a blank line
    arrType2(I) = strTmp
    I = 1 + I
    Line Input #fFile, strTmp
Wend
Close #fFile
ReDim Preserve arrType2(0 To I - 1)
ReDim arrName3(0 To I - 1, 0 To 4)
For I = 0 To UBound(arrType2)
    arrTmp = Split(arrType2(I), ",")
    arrName3(I, 0) = arrTmp(0)
    arrName3(I, 1) = arrTmp(1)
    arrName3(I, 2) = arrTmp(2)
    arrName3(I, 3) = arrTmp(3)
    arrName3(I, 4) = arrTmp(4)
Next
'End of Type 3
''Provide a default button, usually the first in the list
OptionButton1.Value = True
End Sub

Private Sub CancelButton_Click()
Unload Me
End Sub

Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
    ListBox1.Clear
    ListBox1.List = arrName1
    ListBox1.ListIndex = 0
End If
End Sub


Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
    ListBox1.Clear
    ListBox1.List = arrName2
    ListBox1.ListIndex = 0
End If
End Sub

Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
    ListBox1.Clear
    ListBox1.List = arrName3
    ListBox1.ListIndex = 0
End If
End Sub

akdrafter

  • Guest
Re: Total newby to the swamp... VB block insertion
« Reply #27 on: May 18, 2006, 08:04:21 PM »
How do I get that Debug.Print to work? I am pretty sure a person uses it to see what the value of the dim's are.

Bryco

  • Water Moccasin
  • Posts: 1864
Re: Total newby to the swamp... VB block insertion
« Reply #28 on: May 18, 2006, 08:07:27 PM »
akdrafter, a menu is also a very good way of inserting your blocks.
I think you mentioned columns, if you have say 10 columns and they can easily be described by a submenu heading like 10" dia., 8" dia. then it is quicker to grab them from a pull down menu than wait for the gui to load (not much, perhaps I should say less noisey). If there  is no need for a picture of the block then you dont put it in. You can also load a gui from the menu for the items that just suit that format better.

Bryco

  • Water Moccasin
  • Posts: 1864
Re: Total newby to the swamp... VB block insertion
« Reply #29 on: May 18, 2006, 08:08:43 PM »
view-> immediate window