Poll

Will it work?

Yes
9 (100%)
No
0 (0%)
Why try?
0 (0%)

Total Members Voted: 5

Voting closed: December 28, 2003, 06:01:59 PM

Author Topic: Multiple Insert V0.1B  (Read 19118 times)

0 Members and 1 Guest are viewing this topic.

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« on: December 23, 2003, 06:01:59 PM »
Well I am working on something here and I wanted to see if you guys saw any true use for this or if it may be a waste of time.

Psuedo Code / Idea:

1. User has a popup box like this:


2. In the dwg info spot, current dwg ltscale is shown, along with snapang and clayer.

3. Below that is something called 'Blocks'. Here is where all blocks in current dwg are listed (alphabatized).

4. Ins. Layer - Pick the layer that you want all of your blks inserted on to. (Hides xref layers and binds)

5. Uniform Ang. - If user checks the unif. ang. box, this will become active and allow the user to specify a uniform angle for all blks inserted from this prog.

6. New layer name - If user checks 'Create New Layer' this will become active and allow the user to type in a new layer name and ins all blks to that layer.

7. Allow MIRRTEXT - only useful if unif ang is not selected. Allows user to rotate the blocks and have them automatically mirror if needed.

8. Block Preview - previews the blk if a preview is present.

Now I created the form in the VBA module, but have nothing that works...I know nothing of the devil and his ways ;). Do you guys feel that this could be useful or just a fancy way of inserting for beginners?

Let me know what you guys think so I can try to start and write some code for this if this is something worth while doing.

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

daron

  • Guest
Multiple Insert V0.1B
« Reply #1 on: December 23, 2003, 06:07:25 PM »
Only if I can select multiple blocks within a folder and have it insert each block, wherever I select it. BTW Rug, you're allowed to vote too.

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #2 on: December 23, 2003, 06:14:32 PM »
Ok...so multiple blk support, and a browse ability...that shouldn't be too hard. I don't think that it will be at least. Well so far...it doesn't sound to be too much to try for.
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16716
  • Superior Stupidity at its best
Multiple Insert V0.1B
« Reply #3 on: December 23, 2003, 10:05:58 PM »
Anything that there is a use for AND that someone would use AND that make the job easier AND/OR that makes the faster AND/OR makes the job more accurate are always welcome in my book.
 The amount of coding in many programs is seen many times as entirely too much for the end result, but it has been my experience that any bit of code that saves say 2 minutes each drawing and can be reused 3 to 5 times a day or more and makes the job more accurate is certainly worth the effort. The reason is that once the program is written it becomes part of your regular tool kit and you would become more dependent upon it, and find more uses for it. While becoming dependant on a program is not readily viewed as a positive thing by most people, I submit that it is positive in that if you adhere to a set of standards and can then create a series of programs to do larger and increasingly difficult tasks, you reduce the margin of error and increase productivity, not to mention the increased worker satisfaction.

Go for it. Make it work real good...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

hendie

  • Guest
Multiple Insert V0.1B
« Reply #4 on: December 24, 2003, 03:29:32 AM »
go for it !
I agree with Keith's statements.

and if nothing else... you'll learn a bt about VBA so whatever happens you'll have stepped forward in the autocad scheme of things. (BTW shouldn't this post be in the VBA forum ? it's kinda lonely in there  :cry: )

one thing I would like to add is that while you have designed your proggy with specific functions at the moment, you could well find that will change as you develop your programme. And even after you've completed it, you'll probably revisit it to make amendments/additions etc at a later date.
I have a prog here that I wrote about two years ago. I use it at least several times a day and only last week I had a brainwave and made an addition to it ~ saved myself another 15 seconds per dwg !


BTW, you may want to add a "scale" factor in there too

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #5 on: December 24, 2003, 08:13:14 AM »
Ok it seems as though I have a good amount of you wanting to see what can become of this now. As to answer your question Hendie 'BTW shouldn't this post be in the VBA forum ?'..I was thinking that, but there are two ways that I can to this...DCL and VBA...granted the two are completely different, but can accomplish some of the same tasks as one another. Then also about you scale idea...I am going to have to add this...I originally was thinking that I could just use ltscales to determine the scales, but not everyone is CADliterate as some of us may or may not be. Now I will admit that this is going to be my first attempt with anything in VBA...I am getting ready to head over to Afra and Stig's websites to start looking around for some examples and possibly ideas on home to make this fall together. Again guys, I appreciate the help and encouragement.

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #6 on: December 25, 2003, 04:27:40 PM »
Ok...I have been sitting here working on the prog, and ran into something that is bugging me.

Here is the code that I have for my drop down to show all of the layers in a dwg.

Code: [Select]
Private Sub ComboBox1_DropButtonClick()
Dim AllLayers As Object
Dim Layer As Object
'declare local variables

Set AllLayers = ThisDrawing.Layers
'get the layers from the layers collection

For Each Layer In AllLayers
'For each layer ->

    ComboBox1.AddItem Layer.Name
    'Add layer name
   
    Next
   

End Sub


The problem is, is that if I click the drop button more than once...well it adds the layers again and again and....well you get the point.. how would I sneek around this? I tried to chand from ComboBox1_DropButtonClick() to ComboBox1_Click() and a few others, but nothing else does what is needed...any advice?

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #7 on: December 29, 2003, 01:13:37 AM »
Well Here is what I have to this point. I have posted some screen shots that way you can see what I mean. Also here is the code. I really feel that this being my first VBA project, I am doing pretty darn well. The code that is used for the user name retrieval is from cadencoding.com. So here it is..I will post some questions after the pics.









Code: [Select]
Private Sub CDSlink_Click()

Dim nFile As Integer

nFile = FreeFile

Open "\TEMP.URL" For Output As #nFile

Print #nFile, "[InternetShortcut]"

Print #nFile, "URL=http://www.civildraftingservices.com"

Close #nFile

'Launch the browser

Shell "rundll32.exe shdocvw.dll,OpenURL " & "\temp.url", vbNormalFocus

'Delete the temp file

Kill "\TEMP.URL"

End Sub

Private Sub ComboBox1_DropButtonClick()
Dim AllLayers As Object
Dim Layer As Object
'declare local variables

Set AllLayers = ThisDrawing.Layers
'get the layers from the layers collection

For Each Layer In AllLayers
'for every layer listed

    ComboBox1.AddItem Layer.Name
    'add the layer name to the list box
   
    Next
   

End Sub


Private Sub ComboBox2_DropButtonClick()
  Dim AllBlocks As Object
 
  Dim objEnt As Object
  Dim objBlks As Object
  Dim objBlk As Object
  Set AllBlocks = ThisDrawing.Blocks
  For Each objBlk In AllBlocks
  ComboBox2.AddItem objBlk.Name
  Next
    For Each objEnt In AllBlocks
    ComboBox2.AddItem objEnt.Name
    Next
    For Each objBlks In AllBlocks
    ComboBox2.AddItem objBlks.Name
    Next
 
  End Sub

Private Sub CommandButton2_Click()

End

End Sub

Private Sub Frame1_Click()

End Sub

Private Sub Label6_Click()


   Const NoError = 0       'The Function call was successful

      ' Buffer size for the return string.
      Const lpnLength As Integer = 255

      ' Get return buffer space.
      Dim status As Integer

      ' For getting user information.
      Dim lpName, lpUserName As String
     
      Set UsersName = ThisDrawing.Application
     

      ' Assign the buffer size constant to lpUserName.
      lpUserName = Space$(lpnLength + 1)

      ' Get the log-on name of the person using product.
      status = WNetGetUser(lpName, lpUserName, lpnLength)

      ' See whether error occurred.
      If status = NoError Then
         ' This line removes the null character. Strings in C are null-
         ' terminated. Strings in Visual Basic are not null-terminated.
         ' The null character must be removed from the C strings to be used
         ' cleanly in Visual Basic.
         lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
      Else

         ' An error occurred.
         MsgBox "Unable to get the name."
         End
      End If

      ' Display the name of the person logged on to the machine.
      UserString = Val(lpUserName)
     
      Label6.Caption = lpUserName
     
End Sub

Private Sub Swamplink_Click()
Dim nFile As Integer

nFile = FreeFile

Open "\TEMP.URL" For Output As #nFile

Print #nFile, "[InternetShortcut]"

Print #nFile, "URL=http://theswamp.org"

Close #nFile

'Launch the browser

Shell "rundll32.exe shdocvw.dll,OpenURL " & "\temp.url", vbNormalFocus

'Delete the temp file

Kill "\TEMP.URL"
End Sub


Private Sub UserForm_Click()

End Sub


And my questions as always.

1. As you notice between the first and second image, the user name show up, but you must click it...how do I get it to show up at the start instead?

2. Each Time I click on the Layer/blks pulldowns, it loops and keeps adding each time you click it. How do I fix it to stop after one click?

And the biggest question of all...How am I doing so far for just a little encouragement??? Any more requests?

Thx - Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

SMadsen

  • Guest
Multiple Insert V0.1B
« Reply #8 on: December 29, 2003, 04:10:08 AM »
Hey rugaroo,
Splendid job! It's a bad idea to populate dropdowns or listboxes when clicking on/in them. The initial population should be done in the form's Initialize sub.
Only if adding to the lists, you should change the contents but that task should also be done from the 'outside'. For example, if you're adding via a subdialog or an edit field you should let the object that submits the changes edit the content of the lists.

To make it short, clicks in comboboxes should only handle choice of item, not population.

SMadsen

  • Guest
Multiple Insert V0.1B
« Reply #9 on: December 29, 2003, 04:18:32 AM »
To elaborate, create an Initialize sub for your form like below. Notice that blocks are scanned for type - you wouldn't want layout blocks to appear in the dropdown!

Code: [Select]
Private Sub UserForm_Initialize()
  Dim AllBlocks As Object
  Dim objBlk As Object
  Dim AllLayers As Object
  Dim Layer As Object
  'declare local variables

  Set AllLayers = ThisDrawing.Layers
  'get the layers from the layers collection

  For Each Layer In AllLayers
    'for every layer listed
    ComboBox1.AddItem Layer.Name
    'add the layer name to the list box
  Next
   
  Set AllBlocks = ThisDrawing.Blocks
  For Each objBlk In AllBlocks
    'we don't want layout blocks!
    If Not objBlk.IsLayout Then
      ComboBox2.AddItem objBlk.Name
    End If
  Next
End Sub


*now see what you did? I hate that VB language! (reminds me of V*ginal Burb)*

SMadsen

  • Guest
Multiple Insert V0.1B
« Reply #10 on: December 29, 2003, 05:13:09 AM »
Oh by the way. The first question you have is also because you use a click sub to set the username. Put it into the form initializing sub.

As another note, I like to declare external procedures explicitly instead of or in addition to referencing them. That way you know where they are coming from. In your code, the WNetGetUser function comes from out of town, so I would:
1. Declare where it's coming from (see below)
2. Use it in a separate function (also see below)

Alternatively to WNetGetUser, you can use the WScript object in Windows. It can be used for some good information. For example, the WScript.NetWork keeps the username. In the sub below, I've added both WNetGetUser and WScript.

Code: [Select]
'Declare for WNetGetUser:
Private Declare Function WNetGetUser Lib "Mpr.dll" _
   Alias "WNetGetUserA" _
  (ByVal lpName As String, _
   ByVal lpUserName As String, _
   lpnLength As Long) As Long


'Function to find userName with WNetGetUser:
Private Function getUserName() As String
   Const NoError = 0       'The Function call was successful

      ' Buffer size for the return string.
      Const lpnLength As Integer = 255
      ' Get return buffer space.
      Dim status As Integer
      ' For getting user information.
      Dim lpName, lpUserName As String
     
      ' Assign the buffer size constant to lpUserName.
      lpUserName = Space$(lpnLength + 1)
      ' Get the log-on name of the person using product.
      status = WNetGetUser(lpName, lpUserName, lpnLength)
      ' See whether error occurred.
      If status = NoError Then
         ' This line removes the null character. Strings in C are null-
         ' terminated. Strings in Visual Basic are not null-terminated.
         ' The null character must be removed from the C strings to be used
         ' cleanly in Visual Basic.
         lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
      Else
         ' An error occurred.
         lpUserName = ""
         End
      End If
     
      getUserName = lpUserName
     
End Function

'Sample Initialize sub for Form:
Private Sub UserForm_Initialize()
  Dim AllBlocks As Object
  Dim objBlk As Object
  Dim AllLayers As Object
  Dim Layer As Object
  Dim WScriptObj As Object
  'declare local variables
 
  'just in case you didn't set the label field
  'to empty by default
  Label6.Caption = ""

  On Error GoTo noWScriptObject
  Set WScriptObj = CreateObject("WScript.Network")
  Label6.Caption = WScriptObj.Username
  'additional info from the WScript.Network object could
  'e.g. be (don't go overboard in needless info, though):
    'Label7.Caption = WScriptObj.ComputerName
    'Label8.Caption = WScriptObj.UserDomain
noWScriptObject:

  'here you would call getUserName if you don't
  'want to use or have troubles using the WScript
  'object
    'Label6.Caption = getUserName
   
  Set AllLayers = ThisDrawing.Layers
  'get the layers from the layers collection

  For Each Layer In AllLayers
    'for every layer listed
    ComboBox1.AddItem Layer.Name
    'add the layer name to the list box
  Next
   
  Set AllBlocks = ThisDrawing.Blocks
  For Each objBlk In AllBlocks
    'we don't want layout blocks!
    If Not objBlk.IsLayout Then
      ComboBox2.AddItem objBlk.Name
    End If
  Next
End Sub


*still hating this stoopid language*

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #11 on: December 29, 2003, 07:44:38 AM »
Stig -

Thanks for the corrections. I will have to take a look at that and try to implement it in. I may have some questions regarding you comments, and what not, but that won't be until later...

Thx a lot,
Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16716
  • Superior Stupidity at its best
Multiple Insert V0.1B
« Reply #12 on: December 29, 2003, 09:49:29 AM »
Rug there is an enhancement I can see that might be kinda nice to have... If you include the VoloView AvViewX.dll you canhave a much better drawing preview. It is a little slower, but it gives you the entire drawing in a much better view along with the volo view commands in the preview.

Place a AvViewX control on the form and use this code to manipulate it.
To get the AvViewX control on the controls toolbox, right click on the toolbox and select additional controls, then check the Autodesk Volo View Control.
Code: [Select]

 AvViewX1.src = FullPath
 AvViewX1.ZoomExtents
 AvViewX1.ControlTipText = FullPath


You will need to repaint the form after setting the values..

Code: [Select]

 UserForm.Repaint
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Multiple Insert V0.1B
« Reply #13 on: January 04, 2004, 04:17:29 PM »
Here is the latest.

I have uploaded my dvb file, and some more screenshots. Another problem with the blocks pulldow though, it lists dimensions!!! I tried many ways to exclude them, including:

Code: [Select]
Set AllBlocks = ThisDrawing.Blocks
For Each objBlk In AllBlocks
If Not objBlk.DimStyles Then
ComboBox2.AddItem objBlk.name
End If
For Each objBlk In AllBlocks
'we don't want layout blocks!
If Not objBlk.IsLayout Then
ComboBox2.AddItem objBlk.name
End If
Next


But it still shows them and the gives me an error. What should I try? Also, the layers do not show up alphanumerically...is there a way that I can provide this?

KEB -
I like your point with the VoloView, but I will need some help with that a little later.

Stig -
See you were right, and it's amazing how simple my mistake was. Thank you.

insmul.dvb - http://theswamp.org/lilly.pond/rugaroo/insmul.dvb







Maybe you guys can give me some more ideas, or pointers, at this point all would be great...

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16716
  • Superior Stupidity at its best
Multiple Insert V0.1B
« Reply #14 on: January 04, 2004, 07:19:00 PM »
Problem is you are using two For Each loops try this.....

Code: [Select]

'initiate objBlk as a block
Dim objBlk As AcadBlock
'get all of the blocks defined
Set AllBlocks = ThisDrawing.Blocks
'now for every block
For Each objBlk In AllBlocks
'if the first character is not an asterisk
 If Left$(objBlk.Name, 1) <> "*" Then
'add it to the combo box
  ComboBox2.AddItem objBlk.Name
'end if evaluation
 End If
'proceed to the next objBlk
Next objBlk
'release AllBlocks - this isn't necessary but I don't like leaving loose ends
Set AllBlocks = Nothing


Now you have no dimensions (*Dxx) , hatches (*Xxx), anonymous (*Uxx), paperspace (*PaperSpacexx), or modelspace (*ModelSpace) blocks to contend with. Cool huh...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal