Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

Automated Drawing / API Question(s)

ljacobs

New member
I'll try to be brief and accurate in my explanation, but please feel free to share your questions and comments as well as any potential answers.


I've been working for my company some time now, doing shop drawings for pipe fittings and over the past year I've been moving into more advanced projects and tooling to help the company become more efficient. I started with no experience in AutoCAD, Solidworks or any engineering background whatsoever and have been teaching myself as I go.


I've always hated being pulled off a cool new project to do more shop drawings, and have been thinking of ways to semi automate the process. I've been through several different ways involving massive design trees and excel calculations, but none of them have really satisfied me and they've all involved just about as much work, though it's getting simpler for users who may not have a Solidworks background to understand and brings me closer to shifting this duty to others so I can focus on other projects.


The past 2 days I've been studying macros and API and I'm developing a test setup for Elbow pipes before I move onto more complex fittings.


Current Working Setup...


Opens Master_Elbow.sldprt > Prompts for Dimensional Input > Prompts for Job#and Product Description (which it then compiles into save location and filename as variable "SaveName") > Saves File Copy





The Problem...


After it saves a copy with the name and location that was input, I'm stuck...


I want it to open up a Master_Elbow_Drawing.slddwg WHILE changing thereferenced part to the variable "SaveName" (the part we just created).


I've tried recording macros and seeing how it processes the information, but when I re run the macro it won't change the referenced model in the drawing and sticks with the old Master_Elbow.sldprt instead.


I'll have it doing far more after that as well, but nothing that don't believe I can handle based on all that I've learned so far. I just can't seem to find any help related to my current hurdle and would really appreciate any help!
 
Update...


I've found a command, swApp.ReplaceReferencedDocument, that I think will let me do what I'm trying to do either before or after the document opens... But I can't seem to get it to work right. Is there anything I should know regarding the command?


Here is the article in which I found reference to it originally...


[url]http://newsgroups.derkeiler.com/Archive/Comp/comp.cad.solidw orks/2007-06/msg00042.html[/url]


This is the macro I've been debugging with before I put it into the main macro...


Option Explicit
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Const sReferencingDoc As String = "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\master_elbow_drawing.SLDDWG"
Const sOldDoc&nbsp ; As String = "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\master_elbow.SLDPRT"
Const sNewDoc&nbsp ; As String = "C:\Documents and Settings\ljacobs\My Documents\My Drive\T001\Elbow.SLDPRT"


Sub main()


Set swApp = Application.SldWorks
Dim bRet As Boolean


Set swApp = CreateObject("SldWorks.Application")
bRet = swApp.ReplaceReferencedDocument(sReferencingDoc, sOldDoc, sNewDoc)


Set Part = swApp.OpenDoc6("C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\Master Models\master_elbow_dwg.SLDDRW", 3, 0, "", longstatus, longwarnings)
swApp.OpenDoc6 "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\Master Models\master_elbow_dwg.SLDDRW", 3, 0, "", longstatus, longwarnings
Set Part = swApp.ActivateDoc2("master_elbow_dwg - Sheet1", False, longstatus)
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1


End Sub











It will open the file, but the reference file has not changed whether or not I put it before or after the file opens (I read somewhere that it won't work on an opened file).





Any ideas? I'll keep you posted if I find a solution on my own.
 
I'm a moron... Problem solved finally. After3 hours of researching and googling and studying api help manual and all... I had the drawingfilename and extensionas ...


"..../master_elbow_drawing.SLDDWG"


... instead of theCORRECT ...


".../master_elbow_dwg.SLDDRW"











' ************************************************************ ******************
' C:\DOCUME~1\ljacobs\LOCALS~1\Temp\swx1768\Macro1.swb - macro recorded on 03/04/09 by ljacobs
' ************************************************************ ******************
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object


Sub main()


Dim SldWorks As Object
Set SldWorks = CreateObject("SldWorks.Application")
Dim retval As Boolean


referencingDocument = "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\Master Models\master_elbow_dwg.SLDDRW"
ReferencedDocument = "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\Master Models\master_elbow.SLDPRT"
newReference = "C:\Documents and Settings\ljacobs\My Documents\My Drive\Engineering\T001\Elbow.SLDPRT"


retval = SldWorks.ReplaceReferencedDocument(referencingDocument, ReferencedDocument, newReference)


MsgBox retval



End Sub
 

Sponsor

Articles From 3DCAD World

Back
Top