Jump to content

Recommended Posts

Posted

Is it possible to import surface styles from my template using lisp? I asked Claude and the lisp provided inserts all object styles. 

;;-------------------------=={ Import Alignment Styles }==---------------;;
;;                                                                      ;;
;;  Imports Alignment Styles from Power Generation template            ;;
;;  Uses INSERT method to import block with embedded styles            ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;

(defun C:PG-INS-ALIGN ( / template_dwg curecho curlayer block_name *error*)
	
	;; Error handler
	(defun *error* (msg)
		(if curecho (setvar "CMDECHO" curecho))
		(if curlayer (setvar "CLAYER" curlayer))
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ (strcat "\nError: " msg))
		)
		(princ)
	)
	
	;; Save current settings
	(setq curecho (getvar "CMDECHO"))
	(setq curlayer (getvar "CLAYER"))
	(setvar "CMDECHO" 0)
	
	;; Set template path and block name
	(setq template_dwg "C:/WSB-DT/Autodesk/Power Generation/Templates/Utility Scale Solar/RENEWABLES-CT-DESIGN.dwt")
	(setq block_name "TPLT-Alignment-Styles")
	
	;; Check if template file exists
	(if (findfile template_dwg)
		(progn
			(princ "\n----------\nImporting Alignment Styles...")
			
			;; Set layer to 0
			(setvar "CLAYER" "0")
			
			;; Insert block from template
			;; Format: blockname=filepath
			(command "_.INSERT" 
					 (strcat block_name "=" template_dwg) 
					 "0,0,0"    ; Insertion point
					 ""         ; X scale (default)
					 ""         ; Y scale (default)
					 "")        ; Rotation (default)
			
			;; Check if insert was successful
			(if (entlast)
				(progn
					;; Explode the inserted block
					(command "_.EXPLODE" (entlast))
					
					;; Purge the block definition
					(command "._-PURGE" "_B" block_name "_N")
					
					;; Run audit to verify drawing integrity
					(command "._AUDIT" "_Y")
					
					(princ "\n----------\nPower Generation Alignment Styles Have Been Imported!")
				)
				(progn
					(princ "\n----------\nERROR: Block insertion failed!")
					(princ (strcat "\nBlock '" block_name "' not found in template"))
					(princ "\n----------")
				)
			)
			
			;; Restore settings
			(setvar "CLAYER" curlayer)
			(setvar "CMDECHO" curecho)
		)
		(progn
			;; Template file not found
			(setvar "CMDECHO" curecho)
			(princ "\n----------\nERROR: Template file not found!")
			(princ (strcat "\nLooking for: " template_dwg))
			(princ "\nPlease verify the path is correct")
			(princ "\n----------")
		)
	)
	
	(princ)
)

;;----------------------------------------------------------------------;;
;;                        Load Confirmation                             ;;
;;----------------------------------------------------------------------;;
(princ "\n----------")
(princ "\nAlignment Style Import Command Loaded:")
(princ "\n  PG-INS-ALIGN - Import Alignment Styles")
(princ "\n")
(princ "\nNote: Template must contain a block named 'TPLT-Alignment-Styles'")
(princ "\n      with embedded alignment style definitions")
(princ "\n----------")
(princ)

 

Posted (edited)

Getting inside the CIV3D database can be difficult. Its not a straight forward task to just get this item out of a CIV3D dwg. I did a few tasks re CIV3D and often have to look at different spots in the data base than what you would think hold the information your after.

 

One thing I did was a IMPORT Description key sets, as you could only export. I did some other stuff with surface styles, I have a toolbar that allows you to set the current surface style without using Toolspace set contour interval, on/off etc.

 

AlansContours.png.d93822c840ae83075c1941eb0fee256c.png

 

In Civ3D depending on version there is sample code for making different CIV3D objects like import points, make a surface style, I have limited access to CIV3D but the sample code is a few levels deep in the CIV3D directory, they have lisp and .NET examples. I think in later releases they removed some of the sample code. I will see if I can find something.

 

Have a look at this. 
https://www.google.com/search?q=get+alignment+style+detials+civ3d+autolisp&rlz=1C1CHBF_enAU856AU856&oq=get+alignment+style+detials+civ3d+autolisp&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIJCAEQIRgKGKABMgcIAhAhGI8CMgcIAxAhGI8C0gEKMTcxMDRqMGoxNagCCLACAfEFrEvci61nuFXxBaxL3IutZ7hV&sourceid=chrome&ie=UTF-8

 

 

Edited by BIGAL
Posted (edited)

This gets the current styles 

 

(if (not ah:vercheck)(load "vercheck"))
(ah:vercheck)  ; version check see vercheck.lsp
(setq lst '())
(vlax-for j (vlax-get *AeccDoc* 'SurfaceS)
(setq lst (cons (cons (vla-get-name j) j) lst))
)
(princ lst)

 It should be possible to make a single new style using the data from an existing style. I need to dump say a few of the styles to see what is in them. It will take a little while as have to go elsewhere to work on CIV3D. Then use a VLA-add a style. Similar to add description keys.

 

Just a side comment we had a survey dwg form other software so rather than import the styles we just copied all of the other dwg into our company DWT, so everything was set up correct. The dwg had 3faces so we could make a TIN. Sounds easier way.

 

 

vercheck.lsp

Edited by BIGAL

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...