Dear All Master Shi Fus,
I need to add a few equations to a assembly file with a exsiting text file, which is containing a few of equations.
By manually, it could be done, but how to let it automatically? That is why I want to use API to make it done.
However, recording the macro could not record the procedures when I did it manually.
So could you advice me how to program it ?
thanks a lot
regards
Vincent
SolidworksApi macros
Try the attached. It's for 2013 x64
Hi Simon,
I am afraid that the equation mentioned above was not about sketch. It is the function that : SWX pull-down menu : tool >equation
which is working for the relation among the featrue(suppress, unsuppress), dimension, and so on.
so the attched macro file may be not fit.
thank you all the same.
regards
Vincent
Vincent,
See below for a good example of reading and writing equations through the API. You will need to use one of the many non-sw-api ways of reading the text file, then write the equations using the same calls used in the macro linked below. There is no SW API built in to read equations from a text file.
http://www.angelsix.com/cms/downloads/solidworks-macros/23-equation-editor
Hi Josh,
I have tried that macro : edit equation, it is a very useful and fit my intent.
one question left, it came out a error message box, telling the "IF" function equation were error.
However, I copy and paste the equations to text then import to the assembly manually, it was Ok, no error.
I guess that may be some linkage, external reference or something made the equations be warning.
If I want skip the any error , anything and write the equations into SW asm file, how to deal with that code ?
pls help to advise.
I made a screen capture that let you understand it easily.
thanks a lot.
regards
Vincent
Sorry for the confusion - I uploaded the wrong macro! Should have renamed it from Macro1 to something else.
In case you still need it, I have attached the correct one (renamed this time).
Simon
You need to get rid of the "=" sign in your comparison. SolidWorks doesn't like it if your equation contains more "=" signs than the one that makes it an equation. I am surpised if SolidWorks acceps it when you type it in. Reconsider your logic so that you can use > instead of <=. you can use "Not (b>a)" instead of "b<=a"
Hi Simon, and Josh,
thank you both master Shi fus' kindly support.
the macro files you guys provided, were work on adding equations, however, face the same problem, which is the it could not add the equation of IF condition function.
I have tried that change my logic that can use > instead of <=. you can use "Not (b>a)" instead of "b<=a", which Josh mentioned before, but still did not work. So the problem may not be related to the "=" sign.
the equation is as below:
"SCB3-12-ICT-5.Assembly" = if ( 12 < = "D1@草图3" AND "D1@草图3" < = 24 , "unsuppressed" , "suppressed" )
does SW do not support add the IF equation by load string?
pls advise.
regards
Vincent
Hi Simon, and Josh,
thank you both master Shi fus' kindly support.
the macro files you guys provided, were work on adding equations, however, face the same problem, which is the it could not add the equation of IF condition function.
I have tried that change my logic that can use > instead of <=. you can use "Not (b>a)" instead of "b<=a", which Josh mentioned before, but still did not work. So the problem may not be related to the "=" sign.
the equation is as below:
"SCB3-12-ICT-5.Assembly" = if ( 12 < = "D1@草图3" AND "D1@草图3" < = 24 , "unsuppressed" , "suppressed" )
does SW do not support add the IF equation by load string?
pls advise.
regards
Vincent
Which version and service pack are you using? I just tried that equation in 2013 SP5 and it works OK for me.
Ah, the version I use is SWx2013 sp4.0x64bit.
Thanks your feedback, it is very helpful.
Regards
Vincent
You're not using the French language are you? Because SP5 fixed this:
My OS is English version Win7 , and we set the region language to be the Chinese simplify.
The equations I posted above are containing some Chinese words, if they could be added on your swx2013 sp 5, I think it should be ok, the most important things could be the format of the equation.I will test it on next Monday , work day. Cause we are weekend now, in China.and I am hanging out with friends .
Thank you very much for helping me a lot. Have a good day.
Vincent
Vincent,
Try using IIF instead of IF. Sometimes SW doesn't like it when you use IF. Not sure of why, but IIF seems to work more often.
Thanks, seems a goog point....
I may learn the IIf method.
Thank you again
Hi Matt,
It worked, I replaced the "if" with "iif" and without change anything, thank you so much
So greate , you guys helped me a lot!!
regards
Vincent
I had upgraded the service pack to sp5.0 of SWX2013, and it still could not add the equations with that format.
but with Matt's suggestion, change the "if" to be "iif" , then everything works now.
I don't understand what happens though ,my work can move on now.
However I still want to know reason, if you guys have time , pls share your experience.
all the best for you guys, thank you so much
regards
Vincent
Hi Josh,
the problem was be solved by Matt's suggestion:
"Try using IIF instead of IF. Sometimes SW doesn't like it when you use IF. Not sure of why, but IIF seems to work more often."
thanks a lot
regards
Vincent