Layer Insert

Layer Insert

Anonymous
Not applicable
909 Views
12 Replies
Message 1 of 13

Layer Insert

Anonymous
Not applicable
Hai,

I have a symbol drawing.I have to insert in plant drawing.while insert i have to change the layer name.how can i do this in vba.Herewith i enclosed symbol and plant drawing for reference.

Thanks in advance.
bharathi
0 Likes
910 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
This worked for me in A2007:

~'J'~
[code]
Option Explicit

Sub InsertSymbol()
Dim fname As String
fname = ThisDrawing.Path & "\A9.dwg" '<--your symbol drawing name
Dim pt As Variant
Dim strPt As String

With ThisDrawing

pt = .Utility.GetPoint(, vbCr & "Pick an insertion point of block: ")

strPt = Replace(CStr(pt(0)), ",", ".") & "," & _
Replace(CStr(pt(1)), ",", ".") & "," & _
Replace(CStr(pt(2)), ",", ".")
.SetVariable "CLAYER", "INST" '<-- layer name you need
.SetVariable "CECOLOR", "BYLAYER" '<-- color bylayer
.SetVariable "EXPERT", 2 '<-- suppress any prompts
.SetVariable "FILEDIA", 0 '<-- suppress display file dialog box
.SendCommand ("._-insert " & Chr(34) & fname & Chr(34) & vbCr & strPt & vbCr & "1 1 0.0" & vbCr)
.SetVariable "FILEDIA", 1 '<-- restore variable
.SetVariable "EXPERT", 0 '<-- restore variable

End With

End Sub[/code]
0 Likes
Message 3 of 13

Anonymous
Not applicable
Hai,

Thanks.But i need when i insert the symbol in plant drawing, i want to change the layer name....for ex...symbol drawing layer name is "INST".I need to change that Layer name from "INST" to "FLOOR1".whatever the symbol drawing layer, for ex, INST,DIM,BACK,0 like that...finally i insert in plant drawing i need to change layer name.

Thanks in advance,
Bharathi
0 Likes
Message 4 of 13

Anonymous
Not applicable
Sorry, Bharati
Not clearly enough for me
There are two ways:
-you can rename layer
-you can create the new one

~'J'~
0 Likes
Message 5 of 13

Anonymous
Not applicable
Hai Fatty,

yeah..I need to rename the layer...In symbol drawing, layer name is "INST".while insert into plant drawing i have to rename that layer into "Floor1".Herewith I attach some symbol drawing.In that symbols, drawing have CALL,INST layer...i have to rename that "Floor1".

my target is...I have a plant drawing.i have to insert symbol in that, based on EL Value.

for example :

from 0 to 1000 is "Floor1" Layer
1001 to 2000 is "Floor2" Layer

El-100 'a1.dwg for ex: this symbol have "INST" layer. while insert into plant i have to change "Floor1"
El-200 'a3.dwg
El-1000 'd4.dwg

El-2003 'c5.dwg for ex: this symbol have "INST","CALL" layer. while insert into plant i have to change "Floor2"
El-2500 'f8.dwg

Thank you so much,
Bharathi
0 Likes
Message 6 of 13

Anonymous
Not applicable
Hai Fatty,

In My Before Post I didnt attach drawing Files.Herewith i attach File.

Thanks again,
bharathi
0 Likes
Message 7 of 13

Anonymous
Not applicable
Hai Fatty,
I think, i am Confusing you.sorry for poor explanation.here with i attach 2 symbol drawing. if you see this, you can get, what i need..I did this with the help of layer properties manager by manually.Same way i have to do in vba.

1. before_rename_layer
2. after_rename_layer

1.before_rename_layer :
this drawing have Call, Inst Layer.
2.after_rename_layer
I rename into Floor1 Layer.

Thanks in advance,
Bharathi
0 Likes
Message 8 of 13

Anonymous
Not applicable
Hay, Bharati
I'm still working on that
Do not hurry me up, please, be patience
This will be a long story, as you guess
Say 1-2 days or so
I can't to write quickly than I can

~'J'~
0 Likes
Message 9 of 13

Anonymous
Not applicable
Hai Fatty,

Thank you so much...I will wait...

Thanks again,
Bharathi
0 Likes
Message 10 of 13

Anonymous
Not applicable
Here is module code to rename layer in external drawing
with help of ObjectDBX
Keep in mind that it is not complete solution,
it's just a framework only
I don't include in this code check if this layer does exists:

Option Explicit
'
'~ Request reference to AutoCAD/ObjectDBX Common 17.0 Type Library ~'
'
Function openDialog(sPath, sFilter)
Dim oCD, intResult
Set oCD = CreateObject("UserAccounts.CommonDialog")
oCD.Filter = sFilter
oCD.InitialDir = sPath
oCD.flags = &H80000 + &H4 + &H8 '//or 524300 summary
intResult = oCD.showOpen
openDialog = oCD.FileName
End Function


Sub ChangeSymbolLayer()

Dim DwgName As String
Dim objEnt As Object
Dim oDbx As New AxDbDocument

Set oDbx = GetInterfaceObject("ObjectDBX.AxDbDocument.17") '' or 16 for A2005-6
DwgName = openDialog(ThisDrawing.Path, "All Files|*.*|" _
& "AutoCAD Drawings and Templates|*.dwg;*.dwt")
oDbx.Open DwgName

On Error GoTo Err_Control
For Each objEnt In oDbx.ModelSpace
objEnt.Layer = "Floor1"
Next objEnt

oDbx.SaveAs DwgName

Set oDbx = Nothing
Err_Control:
MsgBox Err.Description

End Sub
'//==========================================//'

Again, there is not clearly enough though, where you have
a get EL values?
What is the algorithm to set layer name accordingly
to the symbol drawing name?
e.g.

Select Case dwgName
Case "a1.dwg"
layerName="Floor1"
Case "a2.dwg"
layerName="Floor2"
Case "a3.dwg"
layerName="Floor3"
End select ???

~'J'~
0 Likes
Message 11 of 13

Anonymous
Not applicable
Hai Fatty,

Thanks Fatty.Herewith I enclosed excel sheet.Its a format of sql server table.i get the following values from the table (tag no,inst,x_position,y_position,z_position and symbol path).in z_pos Field have EL Values.i can seperate value

from
EL 102
EL 103
EL 2004

to
102
103
2004

According to Inst, User can select the symbol drawing and save in sql server table.This code i finish.
According to EL Value we have to set Layer name.

Here i do one routine, take z_pos value
from 0 to 2000 -- > "Floor1"
from 2001 to 4000 ---> "Floor2"
from 4001 to 6000 ---> "Floor3"
from 6001 to 8000 ---> "Floor4"
from 8001 to 10000 ---> "Floor5"
from 10001 to 12000 ---> "Floor6"

Like this rountine going on...

according to this table for z_pos - EL 102....

I take 102 and insert drawing --> C:\Base Drawing\d5.dwg and insert into plant drawing "Floor1" Layer.
EL_10080 --- >C:\Base Drawing\h1.dwg ---> "Floor6" Layer

Like this i have to insert...
at this stage i have a problem, while inserting the symbol, the layer is different. for example "INST"...so i need to rename the layer name according to the table like "Floor1" or "Floor2"

I dont know how to rename the layer...so i need your help.I think now you get.Applogies for my poor explanation.

Thanks Again,
Bharathi
0 Likes
Message 12 of 13

Anonymous
Not applicable
Hi Bharati
How iot works:
Open Plant_table.xls
Select just one cell only in colun "E"
Minimize Excel window, but do not close it
Open drawing in which you want to insert
external drawing as block
Load project, then type vbarun
After the Excel will be closed, jump to
AutoCAD and see message
Block should to be inserted in the position
you got from Excel file
Change references to your ACAD version

Your VBA skill is enough to rewrite it
to your needs, I'll busy and could not
helps you further

~'J'~
0 Likes
Message 13 of 13

Anonymous
Not applicable
Hai Fatty,

Thank you so much....What I expect, I get from the your code.....With the help of your code i will finish...Thanks Again...

Cheers,
Bharathi
0 Likes