

Dasty писал(а):Фикус в чем, Вы жмете капу Запись макроса, и работаете в Катьке..... закончили делать какие либо действия, останавлдиваете запись и смотрите результат Ваших действий на языке VBA
А можно ли получить макрос на уже готовый солид. А то не очень получается. Включать запись макроса при создании я не всегда вспоминаю. Если нет, то получается, что для готового изделия писать макрос очень сложный вопрос.
Подскажите пожалуйста.
А можно ли получить макрос на уже готовый солид.
Mihan писал(а):Может кто-нибудь писал макросы для создания источников света(LightSource). Если сохранились исходники выложите пожалуйста, а то очень надо. Просто при записи макроса с созданием какого-либо источника света у меня в макросе ничего не записывается может знает в чем проблема???
Sub CATMain()
' Get the documents collection
Dim oCollection As Documents
Set oCollection = CATIA.Documents
' test if no document is open
If 0 = oCollection.Count Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Get material library
Dim oProductDocument As Document
Set oProductDocument = CATIA.ActiveDocument
' test if the active document is a product
If 0 = InStr(oProductDocument.Name, ".CATProduct") Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Accessing the Root Product
Dim oRootProduct As Product
Set oRootProduct = oProductDocument.Product
' Accessing the collection of rendering lights
Dim oLights As RenderingLights
Set oLights = oRootProduct.GetItem("CATRscRenderingLightVBExt")
Dim MyViewer As Viewer
Set MyViewer = CATIA.ActiveWindow.ActiveViewer
Dim MyLightSource As LightSource
Set MyLightSource = MyViewer.LightSources.ADD
End Sub
The method ADD failed
Set MyLightSource = MyViewer.LightSources.ADD
Sub CATMain()
' Get the documents collection
Dim oCollection As Documents
Set oCollection = CATIA.Documents
' test if no document is open
If 0 = oCollection.Count Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Get material library
Dim oProductDocument As Document
Set oProductDocument = CATIA.ActiveDocument
' test if the active document is a product
If 0 = InStr(oProductDocument.Name, ".CATProduct") Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Accessing the Root Product
Dim oRootProduct As Product
Set oRootProduct = oProductDocument.Product
' Accessing the collection of rendering lights
Dim oLights 'As RenderingLights
Set oLights = oRootProduct.GetItem("CATRscRenderingLightVBExt")
Dim MyViewer As Viewer
Set MyViewer = CATIA.ActiveWindow.ActiveViewer
MsgBox "Общее количество источников " + CStr(MyViewer.LightSources.Count)
Dim MyLightSource 'As LightSource
On Error Resume Next
Dim Arr(2)
For i = 1 To 3
MyViewer.LightSources.Add
Set MyLightSource = MyViewer.LightSources.Item(MyViewer.LightSources.Count)
Arr(0) = 5
Arr(1) = 8
Arr(2) = -2
MyLightSource.PutDirection Arr
If Err.Number = 0 Then
MsgBox CStr(MyViewer.LightSources.Count) + " источник света добавлен успешно"
Else
MsgBox " Облом с " + CStr(MyViewer.LightSources.Count + 1) + " источником света"
Err.Clear
Exit For
End If
Next
End Sub
Methods
o Sub AddActiveLight( CATIARenderingLight iActiveLight)
Adds a new active light to the shooting active lights list.
Sub CATMain()
' Get the documents collection
Dim oCollection As Documents
Set oCollection = CATIA.Documents
' test if no document is open
If 0 = oCollection.Count Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Get material library
Dim oProductDocument As Document
Set oProductDocument = CATIA.ActiveDocument
' test if the active document is a product
If 0 = InStr(oProductDocument.Name, ".CATProduct") Then
MsgBox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Lights"
Exit Sub
End If
' Accessing the Root Product
Dim oRootProduct As Product
Set oRootProduct = oProductDocument.Product
On Error GoTo 0
Dim cShoot 'As RenderingShootings
MsgBox oRootProduct.GetItem("CATRscRenderingShootingVBExt").Count
oRootProduct.GetItem("CATRscRenderingShootingVBExt").Add
MsgBox oRootProduct.GetItem("CATRscRenderingShootingVBExt").Count
Dim aaa 'As LightSource
Set aaa = oRootProduct.GetItem("CATRscRenderingShootingVBExt").Item(oRootProduct.GetItem("CATRscRenderingShootingVBExt").Count)
MsgBox oRootProduct.GetItem("CATRscRenderingLightVBExt").Count
oRootProduct.GetItem("CATRscRenderingLightVBExt").Add
MsgBox oRootProduct.GetItem("CATRscRenderingLightVBExt").Count
aaa.AddActiveLight (oRootProduct.GetItem("CATRscRenderingLightVBExt").Item(1))
End Sub
LightSource.PutDirection Array(5,8,-2)
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2