CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedVBA Coding

 Post Reply Post Reply Page  12>
Author
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Topic: VBA Coding
    Posted: 20.Aug.2007 at 10:23
Hi

Looking for help on adding current layer names in you active drawings to a  combo box?

Let me explain what i would like to do.
 
I designed a userform wich includes your basic layer operations turning ON & OFF, FREEZING, THAW etc, but know i would like to add a another function where you can delete a layer, but when you click the delete button it opens another userform where you can either pick a layer using a command button or select a layer in a combo box.
 
Know the question how would i code the form or combo box to go search for current layers in active drawing and list it in the combo box index.
 
I'm kinda rusty on my vba coding so any kind of help would be appreciated.
 
CheersConfused


Edited by GaryM - 22.Aug.2007 at 15:58
Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 24.Aug.2007 at 22:21
You can look at the ThisDrawing.Layers collection and iterate through it.
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 28.Aug.2007 at 10:33
Thanks for the suggestion, but came right doing it another way... check it out!

Private Sub UserForm_Activate()

  Dim objLayers As AcadLayers
  Dim objLayer As AcadLayer
 
'search for layers in current drawing and add to combo box
For Each objLayer In ThisDrawing.Layers
  frmDelLayer.cboLayerName.AddItem (objLayer.Name)
  Next
End Sub



Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 28.Aug.2007 at 12:07
Yes, this is the ThisDrawing.Layers iteration :-)
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 28.Aug.2007 at 13:21
HI

Now i'm struggling to delete a layer. How would i go about this...
Here is the code i'm using. What i'm actually trying to do is that i want to select from the combo box a layer to delete.

Here is the code i'm using;

Private Sub cmdOk_Click()
On Error Resume Next
  Dim strLayerName As String
  Dim objLayer As AcadLayer
 
  strLayerName = frmDelLayer.cboLayerName.Text
 
  Set objLayer = ThisDrawing.Layers(strLayerName)
    If objLayer Is Nothing Then
      MsgBox "Layer " & strLayerName & " not found"
      Exit Sub
    End If
 
  objLayer.Delete
    If Err Then
      MsgBox "Unable to delete layer: " & vbCr & Err.Description
    Else
      MsgBox "Layer '" & strLayerName & "' deleted"
    End If
  End Sub

Giving me a error: "Object is referenced by other object(s)"

Any ideas on what i'm doing wrong.
Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 28.Aug.2007 at 13:27
The layer your are trying to delete is probably not empty (contains entities, is referenced from a block, etc.). You can only delete empty layers in this way.
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 28.Aug.2007 at 13:39
Smile cool you are quite right.

Autocad gives you the LAYDEL command where you can delete layers with all entities etc. Is there anything similar i could do with vba?

Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 28.Aug.2007 at 13:47
You can either write the code to remove all possible references to this layer or you can run LAYDEL from VBA (through SendCommand).
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
GaryM View Drop Down
Newbie
Newbie


Joined: 20.Aug.2007
Location: South Africa
Status: Offline
Points: 16
Direct Link To This Post Posted: 28.Aug.2007 at 14:16
How would i write the code to remove all possible references.

And the Sendcommand "LAYDEL" just activates the command does not actually delete the layer,  you still l need to do the normal steps after the laydel command is entered.

I want to delete from my delete layer form after selecting the layer from the combo box and clicking ok.
Regards,
Gary Mansfield
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 28.Aug.2007 at 14:28
The code would be quite complex - it would need to go through nested blocks, xrefs, etc.
 
Try to use LAYDEL - with all following options on the commandline - e.g.:
-LAYDEL Name mylayer
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top

Related CAD tips:


 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,078 seconds.