Author Topic: queries in VBA  (Read 1406 times)

0 Members and 1 Guest are viewing this topic.

viva

  • Guest
queries in VBA
« on: September 19, 2006, 05:20:47 AM »
hi everybody,
             iam a newbee in vba.  iam having doubts in VBA.  after running the program, i want 2 check the result whether its working or not. After running the lisp , v can use ! variable for check the result. but  i dont know how 2 check . can anyone help me.

Code: [Select]
   Dim ssetObj As AcadSelectionSet
   Dim mode As Integer
   Dim grpCode(1) As Integer
   Dim dataVal(1) As Variant
   
   Set ssetObj = ThisDrawing.SelectionSets.Add("SS01") --- why they had add "SSO1".
   mode = acSelectionSetAll
   grpCode(0) = 0
   dataVal(0) = "LWPOLYLINE"
     grpCode(2) = 8
   dataVal(2) = "route"
   ssetObj.Select mode, , , grpCode, dataVal
   'ssetObj.Erase
   'ssetObj.Delete

Edit - code tags added
« Last Edit: September 19, 2006, 08:04:07 AM by jonesy »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: queries in VBA
« Reply #1 on: September 19, 2006, 06:07:36 AM »
You can run the IDE in debug mode and "watch" the variables, the same as you can in the Visual Lisp IDE.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Arizona

  • Guest
Re: queries in VBA
« Reply #2 on: September 19, 2006, 06:24:51 AM »
For what you are trying to do, here is a good starting place. The code below moves all blocks to layer 0. It first looks to see if a selection set of that name exists and deletes it if it does. It then creates the Selection set of all entities then filters based on type. It then moves these entities to zero layer and deletes the selection set.
Hope this helps...

Code: [Select]
Option Explicit

Public Sub TestSet(objDoc As AcadDocument)
  Dim objSelSet As AcadSelectionSet
  Dim objSelCol As AcadSelectionSets
  Dim objLayer As AcadLayer
  Dim intType(0) As Integer
  Dim varData(0) As Variant
  Dim objEnt As AcadEntity
  Set objSelCol = objDoc.SelectionSets
  For Each objSelSet In objSelCol
    If objSelSet.Name = "test1" Then
      objSelSet.Delete
      Exit For
    End If
  Next objSelSet
  Set objSelSet = objSelCol.Add("test1")
  intType(0) = 0
  varData(0) = "INSERT"
  objSelSet.Select 5, filtertype:=intType, _
  filterdata:=varData
  For Each objEnt In objSelSet
    Set objLayer = objEnt.Layer
    If Not objLayer.Freeze And objLayer.LayerOn Then
      objEnt.Layer = 0
    End If
  Next objEnt
  Set objSelCol = Nothing
  objSelSet.Delete
End Sub

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: queries in VBA
« Reply #3 on: September 19, 2006, 06:30:07 AM »
should that be
Code: [Select]
objEnt.Layer = "0"? ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Arizona

  • Guest
Re: queries in VBA
« Reply #4 on: September 19, 2006, 06:37:02 AM »
Yes, you are right. It should be a string :-)

viva

  • Guest
queries in VBA
« Reply #5 on: September 19, 2006, 06:40:56 AM »
hi kerry and arizona,
                          thanks for ur reply.  ur support give me some cofident in learning VBA.
 Actually i had written lisp for collecting coordinates of the polylines and stored in list. the same thing i am trying through VBA.
In VBA, i had reached upto collecting the polylines thru selectionset. now i want 2 collect coordinates.

thanks for ur great support

regards
vivek

Bryco

  • Water Moccasin
  • Posts: 1849
Re: queries in VBA
« Reply #6 on: September 19, 2006, 09:24:42 AM »
Quote
why they had add "SSO1".
This is just a name any name will do.
Use Arizona's selectionset test
Quote
  For Each objSelSet In objSelCol
    If objSelSet.Name = "test1" Then
      objSelSet.Delete
      Exit For
    End If
  Next objSelSet

fix your code- grpCode(2) is no good

ctrl+g will bring up your immediate window
Debug.Print will print to that
(or use the locals or watch window as Kerry was saying.
Add below.
 Debug.Print ssetObj.count
 ssetObj.Delete

ssetObj.Erase-will delete  the items in the selectionset-you don't want that.
ssetObj.Delete-will delete the selectionset and not the items in it.

Now you can use a for loop to work with your plines.
Make a collection to add your coordinates.
Dim CoordCol As Collection
Set CoordCol = New Collection

now place your cursor after Collection and hit F1
this will take you to help