I want to lock all my view Representations via vba

I want to lock all my view Representations via vba

k14348
Advocate Advocate
542 Views
3 Replies
Message 1 of 4

I want to lock all my view Representations via vba

k14348
Advocate
Advocate

Hi,

  i Have one main assembly which has 10 view representations. Now i want to lock all the view representations via vba program. Can anybody help.

I tried something. But its not working im attaching my code for corrections.

Public Sub LockViewRep()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oRepMgr As RepresentationsManager
Set oRepMgr = oDoc.ComponentDefinition.RepresentationsManager

Dim oViewReps As DesignViewRepresentations
Set oViewReps = oRepMgr.DesignViewRepresentations

Dim oViewRep As DesignViewRepresentation
Set oViewRep = oViewReps.Item(3)

Dim oLock As Boolean
Set oLock = oViewRep.Locked

End Sub

Thanq,

karthikeyan M

+91-9894814348

0 Likes
Accepted solutions (1)
543 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor

Try this:

 

Public Sub LockViewRep()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oRepMgr As RepresentationsManager
Set oRepMgr = oDoc.ComponentDefinition.RepresentationsManager

Dim oViewReps As DesignViewRepresentations
Set oViewReps = oRepMgr.DesignViewRepresentations

Dim oViewRep As DesignViewRepresentation
For Each oViewRep In oViewReps
    Call oViewRep.Locked = True
Next
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 4

k14348
Advocate
Advocate

Not working. Error file attached.

0 Likes
Message 4 of 4

Owner2229
Advisor
Advisor
Accepted solution

Alright, this should do it:

 

Public Sub LockViewRep()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oRepMgr As RepresentationsManager
Set oRepMgr = oDoc.ComponentDefinition.RepresentationsManager

Dim oViewReps As DesignViewRepresentations
Set oViewReps = oRepMgr.DesignViewRepresentations

Dim oViewRep As DesignViewRepresentation
For Each oViewRep In oViewReps
    On Error Resume Next
    oViewRep.Locked = True
Next
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods