Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open linked 3D model from a CATDrawing VisBasic 1

Status
Not open for further replies.

LucasC

Automotive
Feb 18, 2019
157
Hi all,

I'm new to visbasic and Ive hit a roadblock. I simply want to open the linked 3D model that the CATDrawing is based on. I've looked through the onboard help but it isn't clear (to me) on what to do.

Here's the code I have so far. I'm stuck with "ViewLink" (I underlined the code line) returning a null value. Any suggestions would be appreciated.

-Chris

Sub catmain()

'Get a hold of the active document
Dim Doc1 As Document
Set Doc1 = CATIA.ActiveDocument

'check if a CATDrawing is open
If InStr(Doc1.Name, ".CATDrawing") = 0 Then
MsgBox "The Active Document must be a CATDrawing."
Exit Sub
End If

'get a hold of the drawing document
Dim drwdoc As drawingDocument
Set drwdoc = Doc1

'get a hold of the sheet
Dim drwsheet As drawingSheet
Set drwsheet = drwdoc.Sheets.Item(1)

'get a hold of view 1
Dim View1 As DrawingView
Set View1 = drwsheet.Views.Item(1)


'get a hold of the view link
Dim viewlink As DrawingViewGenerativeBehavior
Set viewlink = View1.GenerativeBehavior.Document.Parent


'asign view link to parameter
Dim link--1 As DrawingView--GenerativeLinks 'added dashes to display correctly in forums
Dim mylink--1 A-s Drawing--ViewGenerativeLinks 'added dashes to display correctly in forums
Set link--1 = viewlink.Generative--Links 'added dashes to display correctly in forums
viewlink.CopyLinksTo (mylink)


'Open the pointed 3D model
CATIA.Documents.Open (mylink)


'Update The drawing





End Sub
 
Replies continue below

Recommended for you

Hi, do you use same name for drawing and for part, if you do, just take drawing name, and open part from location?
 
No, every file has a unique file name.
 
view.GenerativeBehavior.Document return a Document object
not sure its Parent return a DrawingViewGenerativeBehavior you should be able to "watch" this while you debug your code.

did you check view.DrawingViewGenerativeLinks ?

Eric N.
indocti discant et ament meminisse periti
 
You are suggesting the code should be:

Dim viewlink As DrawingViewGenerativeBehavior
Set viewlink = View1.GenerativeBehavior.Document

I'm not sure what you mean by "watch". The 2nd line above is highlighted yellow during debug and it gives "viewlink=nothing"
 
Hi

Code:
Sub CATMain()

    Exe = MsgBox("Please select a view and click OK To Open the Pointed Document "&_
			chr(13)) &_
                        chr(13)) &_
		" This will UNLOCK, ACTIVATE AND VIEW FRAME for the selected view also ", vbOK, "Open the Pointed Document")

Dim InputObject(0)
InputObject(0) = "DrawingView"

Dim DrwSelect As Selection
Set DrwSelect = CATIA.ActiveDocument.Selection

Status = DrwSelect.SelectElement2(InputObject, "Select View", False)

CATIA.StartCommand"Activate View"

Set drawingDocument1 = CATIA.ActiveDocument
Set Sheets = drawingDocument1.Sheets
Set activeSheet = Sheets.ActiveSheet
Set views = activeSheet.Views

	Dim sSel As Selection
    Set sSel = drawingDocument1.Selection
    sSel.Search "CATDrwSearch.DrwView,sel"
    Dim drwView As DrawingView
    Set drwView = sSel.Item(1).Value
    
If Exe = vbOK Then
        drwView.LockStatus = False
        drwView.FrameVisualization = True
End If

Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument

Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets

Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.ActiveSheet

Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views

Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.ActiveView

drawingView1.Activate

Dim FullName
FullName =  drawingView1.GenerativeBehavior.document.ReferenceProduct.Parent.Fullname

Dim DocName
DocName  =  drawingView1.GenerativeBehavior.document.ReferenceProduct.Parent.Name

MsgBox DocName

Set oDrawingSource = CATIA.Documents.Open(FullName)

End Sub

Regards
Fernando

- Romania
- EU
 
Ferdo, another collegue gave me some advice and i have it working. I like some of the added fuctionality you have in your suggestion. Im going to combine them both, thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor