You are on page 1of 5

Public AcadApp As Object

Public PLineObj As Object


Public CircleObj As Object
Public puntoobj As Object
Public TextStyle As Object
Public LayerObj As Object
Private Sub buteval_Click()
txtxlp1.ControlSource = Worksheets("envolv").Cells(22, 2).AddressLocal()
txtxlp2.ControlSource = Worksheets("envolv").Cells(23, 2).AddressLocal()
txtxlp3.ControlSource = Worksheets("envolv").Cells(24, 2).AddressLocal()
txtxlp4.ControlSource = Worksheets("envolv").Cells(25, 2).AddressLocal()
txtxlp5.ControlSource = Worksheets("envolv").Cells(26, 2).AddressLocal()
txtxdmp1.ControlSource = Worksheets("envolv").Cells(22, 3).AddressLocal()
txtxdmp2.ControlSource = Worksheets("envolv").Cells(23, 3).AddressLocal()
txtxdmp3.ControlSource = Worksheets("envolv").Cells(24, 3).AddressLocal()
txtxdmp4.ControlSource = Worksheets("envolv").Cells(25, 3).AddressLocal()
txtxdmp5.ControlSource = Worksheets("envolv").Cells(26, 3).AddressLocal()
txtxdqp1.ControlSource = Worksheets("envolv").Cells(22, 4).AddressLocal()
txtxdqp2.ControlSource = Worksheets("envolv").Cells(23, 4).AddressLocal()
txtxdqp3.ControlSource = Worksheets("envolv").Cells(24, 4).AddressLocal()
txtxdqp4.ControlSource = Worksheets("envolv").Cells(25, 4).AddressLocal()
txtxdqp5.ControlSource = Worksheets("envolv").Cells(26, 4).AddressLocal()
txtxdnp1.ControlSource = Worksheets("envolv").Cells(22, 5).AddressLocal()
txtxdnp2.ControlSource = Worksheets("envolv").Cells(23, 5).AddressLocal()
txtxdnp3.ControlSource = Worksheets("envolv").Cells(24, 5).AddressLocal()
txtxdnp4.ControlSource = Worksheets("envolv").Cells(25, 5).AddressLocal()
txtxdnp5.ControlSource = Worksheets("envolv").Cells(26, 5).AddressLocal()
txtixp1.ControlSource = Worksheets("envolv").Cells(22, 6).AddressLocal()
txtixp2.ControlSource = Worksheets("envolv").Cells(23, 6).AddressLocal()
txtixp3.ControlSource = Worksheets("envolv").Cells(24, 6).AddressLocal()
txtixp4.ControlSource = Worksheets("envolv").Cells(25, 6).AddressLocal()
txtixp5.ControlSource = Worksheets("envolv").Cells(26, 6).AddressLocal()
txtiyp1.ControlSource = Worksheets("envolv").Cells(22, 7).AddressLocal()
txtiyp2.ControlSource = Worksheets("envolv").Cells(23, 7).AddressLocal()
txtiyp3.ControlSource = Worksheets("envolv").Cells(24, 7).AddressLocal()
txtiyp4.ControlSource = Worksheets("envolv").Cells(25, 7).AddressLocal()
txtiyp5.ControlSource = Worksheets("envolv").Cells(26, 7).AddressLocal()
CommandButton1.Visible = True
CommandButton2.Visible = True
CommandButton3.Visible = True
CommandButton4.Visible = True
CommandButton5.Visible = True
ecarga.SetFocus

End Sub
Private Sub butsalir_Click()
End
End Sub
Private Sub CommandButton1_Click()
Dim fil, co As Double
Dim result As Worksheet
Dim i As Variant
Dim eslon, esdiag, inix, iniy, eslq, eslnor, esdiq, esdin As Single
Dim cc, ff, ll, j, k, pos As Integer
Dim superr, r As Range
Dim matr, matex, matexq, matexn As Variant
Dim newparam(1 To 1, 1 To 6) As Double
Dim ww As Workbook
Set ww = ActiveWorkbook
Set result = Worksheets("hoja5")
eslon = Round(txtxlp1.Value, 4)
esdiag = Round(txtxdmp1.Value, 4)
esdiq = Round(txtxdqp1.Value, 4)
esdin = Round(txtxdnp1.Value, 4)
inix = Round(txtixp1.Value, 4)
iniy = Round(txtiyp1.Value, 4)
eslq = eslon
eslnor = eslon
ll = TextBox1.Value
newparam(1, 1) = Val(Replace(FormatNumber(eslon, 4, vbTrue, vbFalse, vbFalse), "
,", "."))
newparam(1, 2) = Val(Replace(FormatNumber(esdiag, 4, vbTrue, vbFalse, vbFalse),
",", "."))
newparam(1, 3) = Val(Replace(FormatNumber(esdiq, 4, vbTrue, vbFalse, vbFalse), "
,", "."))
newparam(1, 4) = Val(Replace(FormatNumber(esdin, 4, vbTrue, vbFalse, vbFalse), "
,", "."))
newparam(1, 5) = Val(Replace(FormatNumber(inix, 4, vbTrue, vbFalse, vbFalse), ",
", "."))
newparam(1, 6) = Val(Replace(FormatNumber(iniy, 4, vbTrue, vbFalse, vbFalse), ",
", "."))

pos = 0
j = 1
For i = 1 To ll
Worksheets("EC1").Cells(2, 1).Value = i
cc = 219 + j * 6
Set r = Worksheets("EC1").Range(Worksheets("EC1").Cells(13, cc), Workshee
ts("EC1").Cells(763, cc + 1))
pos = fil + pos
fil = Application.WorksheetFunction.Count(r) / 2 + 1
Worksheets("EC1").Activate
matr = Range(Cells(13, cc), Cells(11 + fil, cc + 3)).Value
ReDim matex(1 To fil - 1, 1 To 1) As Variant
ReDim matexq(1 To fil - 1, 1 To 1) As Variant
ReDim matexn(1 To fil - 1, 1 To 1) As Variant
For ff = 1 To fil - 1
matex(ff, 1) = Replace((Replace((FormatNumber(Round(eslon *
matr(ff, 1) + inix, 4), 4, vbTrue, vbFalse, vbFalse) & "coma" & FormatNumber(Ro
und(-esdiag * matr(ff, 2) + iniy, 4), 4, vbTrue, vbFalse, vbFalse)), ",", ".")),
"coma", ",")
matexq(ff, 1) = Replace((Replace((FormatNumber(Round(eslq *
matr(ff, 1) + inix, 4), 4, vbTrue, vbFalse, vbFalse) & "coma" & FormatNumber(Ro
und(esdiq * matr(ff, 3) + iniy, 4), 4, vbTrue, vbFalse, vbFalse)), ",", ".")), "
coma", ",")
matexn(ff, 1) = Replace((Replace((FormatNumber(Round(eslnor
* matr(ff, 1) + inix, 4), 4, vbTrue, vbFalse, vbFalse) & "coma" & FormatNumber(
Round(esdin * matr(ff, 4) + iniy, 4), 4, vbTrue, vbFalse, vbFalse)), ",", ".")),
"coma", ",")
Next ff
result.Activate
Range(Cells(pos + 2, j * 3 - 2), Cells(pos + fil, j * 3 - 2)).Value = mate
x
Range(Cells(pos + 2, j * 3 - 1), Cells(pos + fil, j * 3 - 1)).Value = mate
xq
Range(Cells(pos + 2, j * 3), Cells(pos + fil, j * 3)).Value = matexn
result.Cells(pos + 1, 3 * j - 2).Value = ("MEC" & Fo
rmat(i, "0000"))
result.Cells(pos + 1, 3 * j - 1).Value = ("QEC" & Ri
ght(FormatNumber(1000 + i, 0, vbTrue, vbFalse, vbFalse), 3))
result.Cells(pos + 1, 3 * j).Value = ("NEC" & Right(
FormatNumber(1000 + i, 0, vbTrue, vbFalse, vbFalse), 3))

Next i

MsgBox (fil & ll)


End Sub
Sub AcadConectar()
On Error Resume Next
Set AcadApp = GetObject(, "Autocad.Application")
If Err Then
Err.Clear
Set AcadApp = CreateObject("Autocad.Application")
AcadApp.Visible = True
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
If (AcadApp.documents.Count = 0) Then
AcadApp.documents.Add
End If
End Sub
Sub AcadCerrar()
Set AcadApp = Nothing
End Sub
Sub nuevolayerauto(nombrelayer As String, laycolor As Integer)
Set LayerObj = AcadApp.activedocument.layers.Add(nombrelayer)
LayerObj.Color = laycolor
End Sub
Sub polyacad(ppl() As Double, nombrelayer As String)
Set PLineObj = AcadApp.activedocument.modelspace.addlightweightpolyline(ppl)
PLineObj.layer = nombrelayer

End Sub
Sub puntoSsimples(nombrelayer As String, pbx() As Double, pby() As Double, ssini
x, ssiniy, ssesclong, ssescdiag, cc, snpun, laycolor As Integer)
Dim k As Integer
Dim ppl() As Double
ReDim ppl(0 To 2 * snpun - 1)
For k = 1 To snpun
ppl(2 * k - 2) = Round(ssinix + ssesclong * pbx(k), 4)
ppl(2 * k - 1) = Round(ssiniy + ssescdiag * pby(k), 4)
Next k
AcadConectar
nuevolayerauto nombrelayer, laycolor
polyacad ppl(), nombrelayer
End Sub
Sub CommandButton2_Click()
Dim pisoval, necs, i, j, u, idp, npuntos, csolic, colorini, colorpaso, laycolor
As Integer
Dim mneg, cic, cjc, lsup, linf As Integer
Dim errinic As Variant
Dim condinic(1 To 5, 1 To 6) As Double
Dim pbx() As Double, pby() As Double
Dim inix, iniy, esclong, escdiag As Double
Dim rangocontar, rcond As Range
Dim nombrelayer As String
colorini = Worksheets("envolv").Range("b18").Value
colorpaso = Worksheets("envolv").Range("b19").Value
Set rcond = Worksheets("envolv").Range("b22")
For cic = 1 To 5
For cjc = 1 To 6
condinic(cic, cjc) = rcond.Offset(cic - 1, cjc - 1).Value
Next cjc
Next cic

For mneg = 1 To 5
condinic(mneg, 2) = -condinic(mneg, 2)
Next mneg
If ecarga.Value = "" Or pisovaltxt.Value = "" Then
errinic = MsgBox("Falta # piso o # estados de carga", vbInformation, "Error")
Else
pisoval = Val(pisovaltxt.Text)
necs = Val(ecarga.Text)
If pisoval >= 1 And pisoval <= 5 Then
lsup = pisoval
linf = pisoval
ElseIf pisoval = 6 Then
lsup = 5
linf = 1
Else
errinic = MsgBox("Falta # piso o # estados de carga", vbInformation,
"Error")
Exit Sub
End If
For j = linf To lsup
For i = 1 To necs
Worksheets("EC1").Cells(2, 1).Value = i
idp = 219 + j * 6
Set rangocontar = Worksheets("EC1").Range(Worksheets("EC1").
Cells(13, idp), Worksheets("EC1").Cells(763, idp))
npuntos = Application.WorksheetFunction.Count(rangocontar)
For csolic = 1 To 3
Worksheets("EC1").Activate
ReDim pbx(1 To npuntos)
ReDim pby(1 To npuntos)
For u = 1 To npuntos
pbx(u) = Cells(12 + u, idp).Value
pby(u) = Cells(12 + u, idp + csolic).Value
Next u
Select Case csolic
Case 1
nombrelayer = "EC" & Format(i, "000") & "_MOME
NTOS"
Case 2
nombrelayer = "EC" & Format(i, "000") & "_CORT
ANTES"
Case 3
nombrelayer = "EC" & Format(i, "000") & "_NORM
ALES"
End Select
laycolor = colorini + colorpaso * (i - 1)
inix = condinic(j, 5)
iniy = condinic(j, 6)
esclong = condinic(j, 1)
escdiag = condinic(j, 1 + csolic)
puntoSsimples nombrelayer, pbx(), pby(), inix, iniy,
esclong, escdiag, i, npuntos, laycolor
Next csolic
Next i
Next j
End If
Worksheets("envolv").Activate
End Sub

You might also like